var i18n = {
	qzz:{
		useTime:" 耗时{0}毫秒",
		empty:"空白",
		all:"全部",
		monthsText:["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
		weeksText:["日", "一", "二", "三", "四", "五", "六"],
		tendaysText:["上旬","中旬","下旬"],
		current:'当前',
		month:"月",
		merg:"合并/拆分单元格",
		defFontFamily:"宋体",
		paste:"粘贴",
		clear:"清除",
		copy:"复制",
		colset:"列设置",
		copyMsg:"因当前浏览器的剪贴板无法控制，请在IE上使用该功能。",
		dateMaxer:"当前日期，大于最大日期",
		dateMiner:"当前日期，小于最小日期",
		minDate:"最小日期：",
		maxDate:"最大日期：",
		setPositionErr:"设置选择位置报错",
		recordCount:"共{0}条",
		pershow:"每页显示",
		percount:"条记录",
		summary:"合计",
		pageSummary:"小计",
		index:"序号",
		emptyRecord:"<没有任何记录>",
		collapse:"全收缩",
		expand:"全展开",
		mergCell:"合并空的单元格",
		sort_up:"升序",
		sort_down:"降序",
		sort_def:"默认排序",
		clearFilter:"清除筛选",
		inputKey:"输入关键字",
		ok:"确定",
		cancel:"取消",
		noSetupPrinter:"系统没有安装打印机。",
		noPrinter:"无法获取打印机列表，请检查是否已配置受信任站点。",
		noPrinter2:"无法获取打印机列表，请关闭所有浏览器并重新注册客户端。",
		noReg:"客户端打印插件未注册。",
		perPage:"第{0}页(共{1}页)",
		flowIntErr:"流程接口调用错误:",
		queryErr:"查询formatid为：{0}的格式主记录失败!",
		noSchemeErr:"当前方案设置的格式已被删除或者类型是参考模型格式，无法用作打印格式。 ",
		noSchemeInfo:"没有配置打印方案，请先配置再打印。",
		selPrivewScheme:"选择预览方案",
		selPrintScheme:"选择打印方案",
		privewScheme:"预览方案：",
		printScheme:"打印方案：",
		privewRang:"预览范围：",
		printRang:"打印范围：",
		curPage:"当前页",
		pageRange:"页码范围",
		printer:"打印机：",
		printCount:"打印份数:",
		nlower:["〇", "一", "二", "三", "四", "五", "六", "七", "八", "九"],
		nupper:["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"],
		ulower:["", "", "", "点", "", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万亿", "十", "百", "千", "亿亿","十","百", "千", "万"],
	    uupper:["", "", "", "点", "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万亿", "拾", "佰", "仟", "亿亿", "拾", "佰", "仟", "万"],
	    umoneylower:["厘", "分", "角", "整", "元", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万亿", "十", "百", "千", "亿亿","十","百", "千", "万"],
	    umoneyupper:["厘", "分", "角", "整", "圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万亿", "拾", "佰", "仟", "亿亿", "拾", "佰", "仟", "万"],
	    minus:"负" 
	},
	"zh": true
}
//======================================print.xml====================================================

/*

 * Copyright 2010-2020 广东远光软件股份有限公司 All Rights Reserved.
 * 
 * @describe 通用打印xml节点  @author qinzz
 * @version 2013-11-05
 * @see
 * @since JDK 1.4
 */
function printXmlNode(xmlDoc, NodeName, NodeValue, NodeId) {
 	    this.name = NodeName;
		this.value = NodeValue;
		this.id = NodeId;
		this.type = "node";
		this.index;
		this.pNode;
					
		this.attribs = {};
		this.nodes = {};
		this.nodeAry = [];
		
		this.xmlDoc = xmlDoc;
			
		if(NodeId != null) {
			 this.attribs["ID"] = NodeId;
		}		
}

printXmlNode.prototype.isEmpty = function(value) {
		return value == null || value === "";
}

				
printXmlNode.prototype.cloneNode = function(pNode) {
			  var cn = new printXmlNode(this.xmlDoc, this.name, this.value, this.id);
			  cn.pNode = pNode;
			  cn.setAttrib(this.attribs);
			  var tn;
			  for(var name in this.nodes) {
			  	  if(this.nodes[name].type == "array") {
			  	  	  for(var i = 0; i < this.nodes[name]["array"].length; i++) {
							  	  tn = this.nodes[name]["array"][i].cloneNode(cn);
							  	  cn.addNode(tn);
					  }
			  	  } else {
			  	  	  tn = this.nodes[name].cloneNode(cn);
			  	      cn.addNode(tn);
			  	  }
			  }
			  tn = null;				  				  
			  return cn;
		}
			
printXmlNode.prototype.addAryNode = function(ary, node, index) {
			   var len = ary["array"].length;
			   if(index != null && index >= 0 && index < len) {
			        for(var i = len; i > index; i--) {
			            ary["array"][i]  = ary["array"][i - 1];
			            ary["array"][i].index = i;
			        }
			        ary["array"][index] = node;
			        node.index = index;
			        if(node.id != null) {
			            ary["id"][node.id] = node;
			        }
			   } else {
			   	    var ins = ary["array"].length;
			   	    ary["array"][ins] = node;
			        node.index = ins;
			        if(node.id != null) {
			            ary["id"][node.id] = node;
			        }		
			        ins = null;		   
			   }
			
		}
			
			
			
printXmlNode.prototype.addNode = function(name, value, id, index) {
			if(typeof(name) == "object") {					 
				 if(value != null) {
				 	   name.value = value;
				 }
				 value = name;
				 name = value.name;
				 id = value.id;					 
			}
			if(!this.isEmpty(name)) {	
				  var rs;			    
			    if(value != null) {
			    	  if(this.nodes[name] == null) {
				    	  if(typeof(value) == "object") {
				    	     this.nodes[name] = value;
				    	     this.nodeAry.push(value);
				    	  } else {
				    		 var nn = new printXmlNode(this.xmlDoc, name, value, id);
				    	  	 this.nodes[name] = nn;
				    	  	 //store in Ary
				    	  	 this.nodeAry.push(nn);
				          }
				          rs = this.nodes[name];
			        } else {
			        	  var on = this.nodes[name];
			        	  if(on.type === "node") {					        	  
					        	  var ary = {};
					        	  ary["type"] = "array";
					        	  ary["array"] = [];
					        	  ary["id"] = {};
						          this.addAryNode(ary, on);
						          this.nodes[name] = ary;	
						          if(typeof(value) === "object") {
						        	  this.addAryNode(ary, value, index);
						        	  if(index != null && index < this.nodeAry.length) {
						        		  this.nodeAry.splice(index, 0, value);
						        	  } else {
						        	      this.nodeAry.push(value);
						        	  }
						          	  rs = value;
						          	  ins = null;
						          } else {
						          	  var nn = new printXmlNode(this.xmlDoc, name, value, id);
						          	  this.addAryNode(ary, nn, index);
						          	  if(index != null && index < this.nodeAry.length) {
						          		  this.nodeAry.splice(index, 0, nn);
						          	  } else {
						          	      this.nodeAry.push(nn);
						          	  }
						          	  rs = nn;
						          }
						          ary = null;
				          } else {
				          	  var ary = this.nodes[name];
				          	  if(typeof(value) === "object") {
				          		  this.addAryNode(ary, value, index);
				          		  if(index != null && index < this.nodeAry.length) {
					        		  this.nodeAry.splice(index, 0, value);
					        	  } else {
				          		      this.nodeAry.push(value);
					        	  }
				          	      rs = value;
				          	  } else {
				          	  	  var nn = new printXmlNode(this.xmlDoc, name, value, id);
				          	  	  this.addAryNode(ary, nn, index);
				          	  	  if(index != null && index < this.nodeAry.length) {
					          		  this.nodeAry.splice(index, 0, nn);
					          	  } else {
					          	      this.nodeAry.push(nn);
					          	  }
						          rs = nn;
				          	  }
				          	  ary = null;
				          }          
			        	  on = null;
			        }
			    } else {
			    	  if(this.nodes[name] == null) {
			    		  var nn = new printXmlNode(this.xmlDoc, name, undefined, id);
			    	      this.nodes[name] = nn;
			    	      this.nodeAry.push(nn);
			    	      rs = this.nodes[name];
			    	  } else {
			    	  	  var on = this.nodes[name];
			    	  	  if(on.type === "node") {					        	  
					        	  var ary = {};
					        	  ary["type"] = "array";
					        	  ary["array"] = [];
					        	  ary["id"] = {};
					        	  this.addAryNode(ary, on);
						          this.nodes[name] = ary;	
						          if(typeof(value) === "object") {
						        	  this.addAryNode(ary, value, index);
						        	  this.nodeAry.push(value);
						          	  rs = value;
						          } else {
						          	  var nn = new printXmlNode(this.xmlDoc, name, value, id);
						          	  this.addAryNode(ary, nn, index);
						          	  this.nodeAry.push(nn);
						          	  rs = nn;
						          }
						          ary = null;
				          } else {
				          	  var ary = this.nodes[name];
				          	  if(typeof(value) === "object") {
				          		  this.addAryNode(ary, value, index);
				          		  this.nodeAry.push(value);
				          	      rs = value;
				          	  } else {
				          	  	  var nn = new printXmlNode(this.xmlDoc, name, value, id);
				          	  	  this.addAryNode(ary, nn, index);
				          	  	  this.nodeAry.push(nn);
						          rs = nn;
				          	  }
				          	  ary = null;
				          }          
			        	  on = null;
			    	  }
			    }
			    rs.pNode = this;
			    return rs;
			}
		}
			
printXmlNode.prototype.setAttrib = function(name, value, dfNode) {
	             var re = null;
				 if(typeof(name) == "object") {
				 	   for(var n in name) {
				 	   	  this.attribs[n] = name[n];
				 	   	  if(n === "dataField") {				 	   	  	 
				 	   	  	 if(dfNode == null) {
				 	   	  	     var dfs;
					 	   	  	 var pn = this.pNode;
					 	   	  	 while (pn != null && dfs == null) {
					 	   	  	     dfs = pn.getAttrib("dataFields");
					 	   	  	     pn = pn.pNode;
					 	   	  	 }
					 	   	     if(dfs == null) {
					 	   	  	    re = this.xmlDoc.addDataField(name[n], this, dfNode);
					 	   	  	 } else {
					 	   	  	    re = this.xmlDoc.addDataField(dfs + "/" + name[n], this, dfNode);
					 	   	  	 }
				 	   	  	 } else {
				 	   	  	     re = this.xmlDoc.addDataField(name[n], this, dfNode);
				 	   	  	 }				 	   	  	 
				 	   	  } else if(n === "dataFields") {
				 	   		re = this.xmlDoc.addDataFields(name[n], this);
				 	   	  }
				 	   }
				 } else {
				     this.attribs[name] = value;
				     if(name === "dataField") {
				    	 if(dfNode == null) {
				     	     var dfs;
				 	   	  	 var pn = this.pNode;
				 	   	  	 while (pn != null && dfs == null) {
				 	   	  	     dfs = pn.getAttrib("dataFields");
				 	   	  	     pn = pn.pNode;
				 	   	  	 }
				 	   	  	 if(dfs == null) {
				 	   	  	     re = this.xmlDoc.addDataField(value, this, dfNode);
				 	   	  	 } else {
				 	   	  	     re = this.xmlDoc.addDataField(dfs + "/" + value, this, dfNode);
				 	   	  	 }
				    	 } else {
				    		 re = this.xmlDoc.addDataField(value, this, dfNode);
				    	 }
				 	 } else if(name === "dataFields") {
				 	     re = this.xmlDoc.addDataFields(value, this);
				 	 }
				 }
				 return re;
		}
			
printXmlNode.prototype.getAttrib = function(name) {
		     return this.attribs[name];
		}
		
printXmlNode.prototype.getAttribs = function() {
		    return this.attribs;	
		}
		
printXmlNode.prototype.getNodeByIndex = function(name, index) {
			 if(this.type === "array") {
			 	  return this.nodes["name"][index];
			 }
		}
			
printXmlNode.prototype.getNodes = function() {
		    return this.nodes;	
		}
		
printXmlNode.prototype.getPath = function() {
		   var result = "";
		   var cn = this;
		   while(cn != null) {
		   	   if(result !== "") {
		   	      result = "/" + result;
		   	   }				   
				   if(cn.id != null) {
				       result  = cn.name + "&" + cn.id + result;
				   } else if(cn.index != null) {
				       result = cn.name + "&" + cn.index + result;
				   } else {
				       result = cn.name + result;
				   }
				   cn = cn.pNode;
		   }
		   return result;
		}
			
printXmlNode.prototype.getNode = function(path) {
			if(typeof(path) !== "object") {
				path = path.split(/[\\\/]/);
			}		
			var rn = null;
			if(path.length > 0) {
				  var key, id;
				  var pAry = path[0].split("&");
				  key = pAry[0];
				  if(pAry.length == 2){
				     id = pAry[1];	
				  }
					rn = this.nodes[key];
					if(rn != null && rn.type == "array") {
						  if(!this.isEmpty(id)) {
						     	if(isNaN(id)) {
						  	      rn = rn["id"][id];
						  	  } else {
						  	      if(id >= 0 && id < rn["array"].length) {
						  	          rn = rn["array"][id];
						  	      } else {
						  	          rn =	rn["id"][id];
						  	      }
						  	  }
						  } else {
						  	  return rn["array"];
						  }
					}
			}
			if(rn != null && path.length > 1 && rn.type != "array") {
				path.shift();
				return rn.getNode(path);
			} else {
				return rn;
			}
		}

printXmlNode.prototype.delNode = function(path, notFree) {
	var dn = path;
	if(typeof path == "string") {
		dn = this.getNode(path);
	}
	if(dn != null) {
		pn = dn.pNode;
		//json结构删除
		if(pn.type == "array") {
			var pAry = pn["array"];
			var dindex = -1;
			for(var i = 0; i < pAry.length; i++) {
				if(pAry[i].id == dn.id) {
					dindex = i;
					break;
				}
			}
			if(dindex >= 0) {
			    pAry.splice(dindex, 1);
			}
			var pids = pn["id"];
			delete pids[id];
			pAry = null;
			pids = null;
		} else {
			delete pn.nodes[dn.name];
		}
		//数组结构删除
		var pnAry = pn.nodeAry;
		var dindex = -1;
		var cn = null;
		for(var i = 0; i < pnAry.length; i++) {
			cn = pnAry[i]; 
			if(cn.name == dn.name && cn.id == dn.id) {
				dindex = i;
				break;
			}
		}
		if(dindex >= 0) {
			pnAry.splice(dindex, 1);
		}
		cn = null;
		pnAry = null;
		if(notFree != true) {
		    dn.free();
		}
	
	}
	dn = null;
}
		
printXmlNode.prototype.toString = function(template) {
			var result = [];
			var i = 0;
			result[i++] = "<";
			result[i++] = this.name;
			for(var name in this.attribs) {
				if(!this.isEmpty(this.attribs[name]) && typeof this.attribs[name] != "function") {
					  if(template === true || name !== "dataField" && name !== "dataFields") {
					  	  result[i++] = " " + name + "=\"" + this.attribs[name] + "\"";
					  }
				}
			}
			result[i++] = ">";
			//if(template == true) {
			  result[i - 1] += "\n";
			//}
			var hasNode = false;
			if(!this.isEmpty(this.value)) {		
				result[i - 1] = ">";
				var cv = this.value;
				if(template) {
				    if(typeof cv === "string") {
				        cv = cv.replace(/<|>/g,function(key) {
				            if(key === "<") return "&lt;";
							else return "&gt;";
				        });
				    }
				}
				if(cv !== "") {
					result[i++] = "<![CDATA[" + cv + "]]>";					
				} else {
				    result[i++] = this.value;
				}
				hasNode = true;
			}
			for(var j = 0, len = this.nodeAry.length; j < len; j++) {
				result[i] = this.nodeAry[j].toString(template);
				result[i] += "\n";
				i++;
				hasNode = true;
			}
			/*
			for(var name in this.nodes) {
					if(this.nodes[name] != null) {
							if(this.nodes[name].type == "node") {
									result[i++] = this.nodes[name].toString(template);
									//if(template == true) 
									  result[i - 1] += "\n";
									hasNode = true;
						  } else {
						      for(var j = 0; j < this.nodes[name]["array"].length; j++) {
						      	 result[i++] = this.nodes[name]["array"][j].toString(template);
						      	 //if(template == true) {
						      	   result[i - 1] += "\n";
						      	 //}
						      	 hasNode = true;
						      }
						  }
					}
			}
			*/
			if(hasNode) {
					result[i++] = "</";
					result[i++] = this.name;
					result[i++] = ">";
		  } else {
		  	  result[i - 1] = "/>";
		  }
			return result.join("");
		}

printXmlNode.prototype.free = function() {
	var name;
	for(name in this.attribs) {
		this.attribs[name] = null;
	}
	this.attribs = null;
	
	for(name in this.nodes) {
		if(this.nodes[name].type == "node") {	
			this.nodes[name].free();
			this.nodes[name] = null;
		} else {
			var cnodeAry = this.nodes[name]["array"];
			if(cnodeAry != null) {
				for(var j = 0; j < this.nodes[name]["array"].length; j++) {
					this.nodes[name]["array"][j].free();
					this.nodes[name]["array"][j] = null;
				}
			}
			cnodeAry = null;
			this.nodes[name]["array"] = null;
			this.nodes[name] = null;
		}
	}	
	this.nodes = null;
	this.nodeAry = null;

	this.name = null;
	this.value = null;
	this.id = null;
	this.type = null;
	this.index = null;
	this.pNode = null;	
	this.xmlDoc = null;
}


function printXmlDoc() {			
	 this.attribs = {"version":"1.0", "encoding":"gb2312"}; 			 
 	 this.topNode = {}; 	 
 	 this.dataFields = [];
 	 this.dataField = {}; 	 
 	 this.pnode = []; 	 
}

printXmlDoc.prototype.isEmpty = function(value) {
	return value == null || value === "";
}

 	 
printXmlDoc.prototype.addDataField = function(name, node, dfNode) {
 		 	  var nameAry = name.split(/[\\\/]/g);
 		 	  if(nameAry.length == 1 && dfNode == null) {
 		 		 if(this.dataField[nameAry[0]] == null) {
 		 			this.dataField[nameAry[0]] = node;
 		 		 } else {
 		 			var cdf = this.dataField[nameAry[0]].childDataField;
 		 		    if(cdf == null) {
 		 		    	cdf = []; 		 		    
 		 		    	this.dataField[nameAry[0]].childDataField = cdf;
 		 		    }
 		 		    cdf.push(node);
 		 		 }
 		 	  	 return true;
 		 	  } else {
 		 		  var nalen = nameAry.length;
 		 		  if(dfNode == null && nalen == 2) {
 		 			 dfNode = this.getDataFields(nameAry[0]);
 		 		  }
 		 	      if(dfNode != null) {
 		 	     	 if(dfNode["cnode"] == null) {
 		 	     		dfNode["cnode"] = {};
 		 	         }
 		 	     	 if(dfNode["cnode"][nameAry[nalen - 1]] == null) { 		 	     	 
 		 	     	     dfNode["cnode"][nameAry[nalen - 1]] = node;
 		 	     	 } else {
 		 	     		var cdf = dfNode["cnode"][nameAry[nalen - 1]].childDataField;
 	 		 		    if(cdf == null) {
 	 		 		    	cdf = []; 		 		    
 	 		 		    	dfNode["cnode"][nameAry[nalen - 1]].childDataField = cdf;
 	 		 		    }
 	 		 		    cdf.push(node);
 		 	     	 }
 		 	         return true;
 		 	     }
 		 	     return false;
 		 	  }
 		 }
 		 
printXmlDoc.prototype.setDataField = function(name, value) {
 		 	  if(this.dataField[name] != null) {
 		 	      this.dataField[name].value = value;
 		 	      cdf = this.dataField[name].childDataField; 		 	      
		 	      if(cdf != null) {
		 	    	  for(var i = 0, len = cdf.length; i < len; i++) {
		 	    		  cdf[i].value = value;
		 	    	  }
		 	      }
 		 	  }
 		 }

printXmlDoc.prototype.addDataFields = function(name, node) {
	            var dfs = {
		            	"name":name,
		            	"node":node
		            };
	            this.dataFields.push(dfs);
	            return dfs;
 		 }

printXmlDoc.prototype.getDataFields = function(name, index) {
	var rn = null;
	for(var i = 0, len = this.dataFields.length; i < len; i++) {
		if(this.dataFields[i].name === name) {
			if(typeof index == "number" && index > 0) {
				index --;
			} else {
				rn = this.dataFields[i];
				break;
			}
		}
	}
	return rn;
}

 		 
printXmlDoc.prototype.setDataFields = function(name, nodes, pnode) {
	var dfs = name
	if(typeof name === "string") {
		dfs = this.getDataFields(name);
	}	
	if(dfs == null) {
		return false;
	}
    if(pnode == null) {
    	pnode = dfs;
    }
    var colWidths = pnode.node.pNode.getAttrib("TdWidths");
	if(colWidths == null || colWidths === "") {
		colWidths = []
	} else if(typeof colWidths == "string") {
		colWidths = colWidths.split(/,/g);
	}    
 	for(var cname in nodes) {
 		var cnode = pnode["cnode"][cname];
 	    if(cnode == null) {
 	    	cnode = pnode["cnode"][cname.toUpperCase()];
 	    }
 		if(cnode != null) {
 			var val = nodes[cname];
 			if(val == null) {
 				val = nodes[cname.toUpperCase()];
 			} 			
 			if(val != null && typeof val == "string" && val.indexOf("<img") >= 0) {
 				//如果有图片
 				var src = val.match(/src='([^<> ]+)'[ \/]*>/);
 				if(src != null && src.length > 0) {
 					src = src[1]; 				
	 				var imgNode = cnode.addNode("Img");
	 				var align = cnode.getAttrib("Alignment");
	 					 				
	 				var x = 2;	 				
	 				if(align == "center") {
	 					x = parseInt(parseInt(colWidths[cnode.index], 10)/2, 10) - 16;
	 				} else if(align == "right") {
	 					x = parseInt(colWidths[cnode.index], 10) - 16;
	 				} 				
	 				
					imgNode.setAttrib({"X":x,"Y":2,"Height":16,"Width":18});
					if(src.indexOf("http://") < 0) {
						if(src.indexOf("/") !== 0) {
							src = "/" + src;
						}					
						src = "http://127.0.0.1:9080" + src;
					}
					imgNode.addNode("Value", src);
					imgNode = null;
				} else {
					cnode.value = val;				
				}
 			} else { 			
 			    cnode.value = val;
 			    for(var i = cnode.nodeAry.length - 1; i >= 0; i--) {
 			    	cnode.delNode(cnode.nodeAry[i], true);
 			    }
 			}
 		}
	}
	return true;
}
 		 
printXmlDoc.prototype.appendDataFields = function(name) {
	var dfs = name;
	if(typeof name === "string") {
		dfs = this.getDataFields(name);
		if(dfs == null) {
			return false;
		}
	}
	var an = dfs["node"]
	if(an != null) {
		var nn = an.cloneNode();
	   	if(an.pNode != null) {  	
	   	    var index = 0;
	   	 	if(an.index != null) {
	   	 	   index = an.index;
	   	 	}	 	    	 	   
	   	    an.pNode.addNode(nn, undefined, undefined, index+1);
	   	}
	   	dfs["node"] = nn;
	   	var nary = nn.nodeAry;
	   	var dfcn = dfs["cnode"];
	   	for(var i = 0, len = nary.length; i < len; i++) {
	   		var cn = nary[i];
	   		cn.value = "";
	   		var sdf = cn.getAttrib("dataField");
	   		if(dfcn[sdf] != null) {
	   			dfcn[sdf] = cn;
	   		}
	   	}
    }
    return dfs["node"];
}
 		 	    
 		 
printXmlDoc.prototype.setAttrib = function(name, value) {
				 if(typeof(name) == "object") {
					var narb;				 
				 	for(var n in name) {
				 	    narb = name[n];				 	   
				 		if(!this.isEmpty(narb)) {
				 	   	    this.attribs[n] = narb;
				 		}
				 	}
				 	narb = null;
				 } else {
					 if(!this.isEmpty(value)) {
				         this.attribs[name] = value;
					 }
				 }
		}
 		 
printXmlDoc.prototype.addNode = function(name, value, id) {
 		 	   var xn = new printXmlNode(this, name, value, id);
 		 	   this.topNode[xn.name] = xn;
 		 	   return xn
 		 }
 		 
printXmlDoc.prototype.getNode = function(path) {
		if(typeof(path) !== "object") {
			path = path.split(/[\\\/]/);
		}		
		var rn = null;
		if(path.length > 0) {
			  var key, id;
			  var pAry = path[0].split("&");
			  key = pAry[0];
			  if(pAry.length == 2){
			     id = pAry[1];	
			  }
			  rn = this.topNode[key];
			  if(rn != null && rn.type == "array") {
				  if(!this.isEmpty(id)) {
				      if(isNaN(id)) {
				  	      rn = rn["id"][id];
				  	  } else {
				  	      if(id >= 0 && id < rn["array"].length) {
				  	          rn = rn["array"][id];
				  	      } else {
				  	          rn =	rn["id"][id];
				  	      }
				  	  }
				  } else {
				  	  return rn["array"];
				  }
			 }
		}
		if(rn != null && path.length > 1 && rn.type != "array") {
			path.shift();
			return rn.getNode(path);
		} else {
			return rn;
		}
}	

printXmlDoc.prototype.trim = function(str) {
		if(str != null && str !== "" && typeof str == "string") {
			str = str.replace(/(^\s*)|(\s*$)/g,"");
		}
		return str;
}
 		 
 		 
printXmlDoc.prototype.initXml = function(nodeAry, bindex, callBack) {
 		 	  var atbRe = /((?!\")?[^<>\"=\/ ]+(?!\")?)/g;
 		 	  //((?!\")?[\w.#,\\]+(?!\")?)/g;
			  var atbTxt = /<\!(--)?\[CDATA\[([^<>]+)\]\](\1)?>/g;
 		 	  var atbAry;
 		 	  var i = bindex;
 		 	  var curNode, tmpNode;
 		 	  var nlen = nodeAry.length;
 		 	  var clen = nlen + 4000;
 		 	  var dataFields = null;
 		 	  for(; i < nlen && i < clen; i++) {
 		 	  	  var cstr = nodeAry[i];
                  if(/<\!(--)?\[CDATA\[/.test(cstr)) {
                       cstr = cstr.replace(atbTxt, "$2");
                  }
 		 	  	  if(cstr.indexOf("</") == 0) {
 		 	  	 	    var cnode = this.pnode.pop();
 		 	  	 	    if(dataFields != null && cnode === dataFields.node) {
 		 	  	 	    	dataFields = null;
 		 	  	 	    }
 		 	  	  } else if(cstr.indexOf("<") >= 0) {  
 		 	  	        if(cstr.indexOf("<!--") >= 0) {
		 		 		    //tmpNode = this.pnode.pop();
			 	    	    //curNode = tmpNode.addNode(cstr);
			 	    	    //this.pnode.push(tmpNode); 		 	  	            
 		 	  	        } else { 		 	  	  
	 		 	  	 	    atbAry = cstr.match(atbRe);
	 		 	  	 	    if(atbAry != null && atbAry.length > 0) {
	 		 	  	 	        if(this.pnode.length == 0) {
		  		 	  	  	  	    curNode = new printXmlNode(this, atbAry[0]);
		  		 	  	  	  	    this.topNode[curNode.name] = curNode;
	 		 	  	  	        } else {
	 		 	  	  	      	    tmpNode = this.pnode.pop();
	 		 	  	 	    	    curNode = tmpNode.addNode(atbAry[0]);
	 		 	  	 	    	    this.pnode.push(tmpNode);
	 		 	  	 	        }
	 		 	  	 	        var arbNode = null;
	  		         	        for(var j = 1; j < atbAry.length; j = j + 2) {	
	  		         	        	arbNode = curNode.setAttrib(atbAry[j], atbAry[j + 1], dataFields);
	  		         	        	if(arbNode != null && typeof arbNode == "object") {
	  		         	        		dataFields = arbNode;
	  		         	        	}
	  		         	        }
	  		         	        if(atbAry != null && cstr.lastIndexOf("/>") < 0) {
					  		        this.pnode.push(curNode);
			  		            }
	  		              }//IF		  		          
	  		          }//ELSE
 		 	  	  } else if(cstr !== "\n" && cstr != null && this.trim(cstr) !== ""){
 		 	  	  	   curNode = this.pnode.pop();
 		 	  	 	   curNode.value = cstr.replace(/&lt;|&gt;/g, 
 		 	  	 	       function(key){
 		 	  	 	           if(key==="&lt;") {
 		 	  	 	               return "<";
 		 	  	 	           } else {
 		 	  	 	               return ">";
 		 	  	 	           }
 		 	  	 	       });
 		 	  	 	   this.pnode.push(curNode);
 		 	  	  }
 		 	  } 
 		 	  if(i < nlen) {
 		 		  var _owner = this;
 		 	      setTimeout(function(){_owner.initXml(nodeAry, i, callBack)}, 0);	
 		 	  } else {
 		 		  if(typeof(callBack) == "function") {
 		 			  callBack();
 		 		  }
 		 	  }
 		 }

printXmlDoc.prototype.setXml = function(xmlStr, callBack) {
 		 	 var atbRe = /((?!\")?[^<>\"= ]+(?!\")?)/g;
 		 	 //((?!\")?[\w.#,]+(?!\")?)/g;
 		 	 var noRe = /((?!>)[^<>]+(?=<))|(<(\/)?[^<>]+(\/)?>)/g;
 		     var strAry = xmlStr.match(noRe);
 		     var bindex = 0;
 		     if(strAry != null && strAry.length > 0) {
	  		     var str = strAry[bindex];
	  		    
	  		     if(str != null && str.indexOf("<?") >= 0) {
	  		         var abAry = str.match(atbRe);
	  		         if(abAry != null && abAry.length > 0) {
	  		         	   for(var i = 1; i < abAry.length-1; i = i + 2) {
	  		         	   	  this.attribs[abAry[i]] = abAry[i+1];
	  		         	   }
	  		         }
	  		         bindex ++;
	  		     }
	  		     this.initXml(strAry, bindex, callBack);
 		     } else if(typeof callBack == "function") {
 		    	callBack(); 
 		     } 		     
 		 }

printXmlDoc.prototype.setEmpty = function() {
	var name;
	for(name in this.topNode) {
	 	this.topNode[name].free();
	 	this.topNode[name] = null;
	}
	for(name in this.dataFields) {
		this.dataFields[name] = null;
	}
	for(name in this.dataField) {
		this.dataField[name] = null;
	}
	this.topNode = {}; 	 
 	this.dataFields = [];
 	this.dataField = {}; 	 
 	this.pnode = []; 	
}
 		 
printXmlDoc.prototype.toString = function(template) {
 		 	  var result = [];
 		 	  var i = 0;
 		 	  result[i++] = "<?xml";
 		 	  for(name in this.attribs) {
 		 		 if(typeof this.attribs[name] != "function") { 		 	  
 		 	         result[i++] = " " +  name + "=\"" + this.attribs[name] + "\"";
 		 		 }
 		 	  }
 		 	  result[i++] = "?>";
 		 	  if(template == true) { 
 		 	    result[i - 1] += "\n";
 		 	  }
 		 	  for(name in this.topNode) {
 		 		  if(typeof this.topNode[name] != "function") { 		 	  
 		 	  	      result[i++] = this.topNode[name].toString(template);
 		 		  }
 		 	  }
 		 	  return result.join("");
 		 }

   //============================================Class==================================================
   //在继承时，不执行构造函数


	var initializing = false;
	/**
	 * 定义类
	 * 
	 * @baseClass 基类
	 * @childClass 子类
	 * @isBind 是否将方法绑定到当前类，将this关键字固定成当前类，就算apply、call方法都无法影响其this的值
	 */
	if(window.qzz == null) {
		window.qzz = {};
	}
	if(window.ecp == null) {
		window.ecp = {};
	}
	window.qzz.index = 0;
	window.qzz.Class = function(baseClass, childClass, isBind) {
		// 兼容jClass({}, true)的情况
		if(typeof childClass === "boolean"){
			isBind = childClass;
		}
		// 只接受一个参数的情况 - jClass(childClass)
		if (typeof (baseClass) === "object") {
			childClass = baseClass;
			baseClass = null;
		}
		/**
		 * 构造新的对象，本次调用所创建的类（构造函数）
		 */
		function curClass() {
			// 如果当前处于实例化类的阶段，则调用init原型函数
			if (!initializing) {
				// 如果存在初始化方法才执行
				if(typeof this.init == "function") {
				    this.init.apply(this, arguments);
				}
			}
		}	
		/** 
		 * 合并同名函数
		 * 把两个对象的同名函数，并排起来，默认调用子类函数， 
		 * 并在执行时，把基类函数赋给this.base，拱子类函数可以调用，
		 * 如此可以起到不改变结构的情况下，能灵活调用基类函数
		 */
		function mergeFunc(funcName) {
		    //定义一个新函数体
			var func = function() {
				//把原来的base先缓存起来
				var _base = this.base;
				//把当前的基类函数放到this.base对象，以便在子类的同名方法中调用。
				this.base = baseClass.prototype[funcName];
				//执行子类的方法，并把结果返回
				var result = childClass[funcName].apply(this, arguments);
				//还原基类的this.base函数
				this.base = _base;
				//返回执行结果
				return result;
			};
			//返回函数体
			return func;
		}
		
		// 如果此类需要从其它类扩展
		if (baseClass) {
			initializing = true;
			//结构指向基类，在javascript结构上会形成类似继承的关系
			curClass.prototype = new baseClass();
			curClass.prototype.constructor = curClass;
			initializing = false;
		}
			
		// 覆盖父类的同名函数 通过prototype定义的函数
		for (var name in childClass) {
			if (childClass.hasOwnProperty(name)) {
				//如果此类继承自父类baseClass并且父类原型中存在同名函数name
				if (baseClass && typeof (childClass[name]) === "function" 
				    && typeof (curClass.prototype[name]) === "function") {
					//合并函数
					curClass.prototype[name] = mergeFunc(name);
				} else {
					curClass.prototype[name] = childClass[name];
				}
			}
		}
			
		// 复制静态方法 不通过prototype定义的函数
		for(var name in baseClass){
			if(typeof baseClass[name] !== "function") continue;
			curClass[name] = baseClass[name];
		}
		
		//通过bind方法给每个方法的this绑定当前对象，避免丢失
		if(isBind){
			for(var name in curClass.prototype){
				if(typeof curClass.prototype[name] === "function"){
					curClass.prototype[name] = curClass.prototype[name].bind(this);
				}
			}
		}		
		//curClass.index = window.qzz.index;
		return curClass;
	};
	window.qzz.space = function(spaceStr) {
		var spa = spaceStr.split(".");
		var qg = window.qzz;
		for(var i = 0, len = spa.length; i < len; i++) {
			if(spa[i] != null && spa[i] !== "") {
				if(qg[spa[i]] == null) {
				    qg[spa[i]] = {};
				}
				qg = qg[spa[i]];
			}
		}
	};
	//return window.qzz.Class;
	//=================================================Object==================================================
	var qzz = window.qzz;
	/**
	 * 基础控件类
	 * @class BaseObject
	 * @author qinzhenzhou@ygsoft.com
	 * @date 2014.3.1
	 */
	qzz.object = qzz.Class(/** @lends BaseObject */{
		/**
		 * 初始化方法，合并处理界面和元模型的属性.
		 * @param {object} option 属性
		 */
	    init:function(option) {
	    	try {
	    		this.index = window.qzz.index++;
	    		
				var defaultOption = this.getDefaultOption();
				
				this.option = this.isEmpty(defaultOption) ? option || {} : this.extend(defaultOption, option);

				this._i18n = i18n;
			    //是否是控件对象的判断变量
			    this.isComponent = true;
			    var metaItem;
				option = option || {};
				if(option && option._merger){
					metaItem = option;
					option = metaItem.inputer.option;
				}
				//数据源
			    this.className = "Object";
			    this._events = {};
			    this._create();
	    	} catch(e) {
	    		this.logInfo("init error:" + e.message + e.stack);
	    	}
	    },
	    /**
	     * 创建函数.
	     */
	    _create:function(){
	    	
	    	this.beginDate = null;
	    	this._lockDestroy = false;
	    	this._hasDestroy = false;
	    	//事件绑定
	    	//this.logInfo("BaseObject.create");
	    },
	    /**
	     * 绑定单击事件.
	     * @param {Function} func 函数体
	     * @param {Object} owner 作用域
	     */
	    click:function(func, owner) {
	    	this.bind("click", func, owner, true);
	    },
		/**
		 * 绑定Ecp事件.
		 * @param {String} method 方法名称,字符串 
		 * @param {Object} event 事件的常量参数
		 * @param {Function} func 函数对象  
		 * @param {Object} owner 作用域
		 * @param {Boolean} override 是否覆盖
		 * @example 
		 *  #method名称 ："click"
		 *  #func : function() {alert("AAA");}
		 *  #component ：子控件对象
		 *  component.bindEcpEvent("mousedown",function(){to do something});
		 *  component.bindEcpEvent("mousedown",{"A":1,"B":2}, function(){to do something}, grid, true | false);
		 */
	    bindEcpEvent:function(method, event, func, owner, override) {
	    	this.bind(method, event, func, owner, override);
	    },
    	/**
		 * 绑定事件.
		 * @param {String} method 方法名称,字符串 
		 * @param {Object} event 事件的常量参数
		 * @param {Function} func 函数对象  
		 * @param {Object} owner 作用域
		 * @param {Boolean} override 是否覆盖
		 * @example 
		 *  #method名称 ："click"
		 *  #func : function() {alert("AAA");}
		 *  #component ：子控件对象
		 *  component.bind("mousedown",function(){to do something});
		 *  component.bind("mousedown",{"A":1,"B":2}, function(){to do something}, grid, true | false);
		 */
	    bind:function(method, event, func, owner, override) {
	    	 if(typeof event == "function") {
	    		 override = owner;
	    		 owner = func;	    		 
	    		 func = event;
	    		 event = undefined;
	    	 }
	    	 if(typeof owner == "boolean") {
	    		 override = owner;
	    		 owner = undefined;
	    	 }
	    	 if(this.isEmpty(this._events[method]) || override) {
	    		 //新增加
	    	    this._events[method] = [{"func":func,"event":event,"owner":owner}];
	    	    func._funcSourceId = 0;
	    	 } else {
	    		//添加
	    		var len = this._events[method].length;
	    		this._events[method].push({"func":func,"event":event,"owner":owner});
	    		func._funcSourceId = len;
	    	 }
	    },
	    /**
	     * 取消绑定的事件，如果要求取消绑定的事件不存在，则返回false
	     * @param {String[] | String} method 函数名或函数名数组.
	     * @param {Function[] | Function} func 函数数组
	     * @returns {Boolean} 如果method为空，则返回false，否则返回true
	     */
	    unbind:function(method, func) {
	    	if(this.isEmpty(method)) {
	    		return false;
	    	}
	    	if(typeof method == "string") {
	    		method = [method];
	    		func = [func];
	    	}
	    	//去除指定函数
	    	for(var i = 0, len = method.length; i < len; i++) {
	    		var mt = method[i];
	    		var fc = func[i];
		    	if(this.isNotEmpty(this._events[mt]) && this.isNotEmpty(mt)) {
		    		if(this.isEmpty(fc)) {
		    			//直接清空
		    			this._events[mt] = [];
		    		} else if(this.isNotEmpty(fc._funcSourceId)){
		    		    var funcLen = this._events[mt].length;
		    		    var index = -1;
		    		    for(var j = 0; j < funcLen; j++) {
		    		    	var funObj = this._events[mt][j];
		    		    	if(funObj.func != null && funObj.func._funcSourceId === fc._funcSourceId) {
		    		    		index = j;
		    		    		break;
		    		    	}
		    		    }
		    		    //从数组中清除
		    		    if(index >= 0) {
		    		        this._events[mt].splice(index, 1);
		    		    }
		    		}
		    	}
		    	mt = null;
		    	fc = null;
	        }
	    	return true;
	    },
	    /**
	     * 判断是否已绑定过事件.
	     * @param {String} method 事件名
	     * @returns {Boolean} 
	     */
	    hasbind:function(method) {
	    	return this._events[method] != null && this._events[method] !== "";
	    },
	    /**
	     * 判断是否已绑定过事件.
	     * @param {String} method 事件名
	     * @returns {Boolean} 
	     */
	    hasBind:function(method) {
	    	return this.isNotEmpty(this._events[method]);
	    },
	    /**
	     * 激活事件.
	     * @param {String} method 事件名
	     * @example
	     *    //绑定事件
	     *    grid.bind("click", function(ent, key) {
	     *        if(key == 13) {
	     *            alert(key);
	     *        }
	     *    })
	     *    //激活事件
	     *    grid.triggerEcpEvent("click", [ent, key]);
		 * @author qzz
		 * @version 1.0
		 * @date 2014-7-2
	     */
	    triggerEcpEvent:function(method) {
	    	return this.trigger.apply(this, Array.prototype.slice.call(arguments));
	    },
	    /**
	     * 激活事件.
	     * @param {string} method 事件名
	     * @param {object} params 参数
	     * @example
	     *    //绑定事件
	     *    grid.bind("click", function(ent, key) {
	     *        if(key == 13) {
	     *            alert(key);
	     *        }
	     *    })
	     *    //激活事件
	     *    grid.triggerEvent("click", [ent, key]);
		 * @author qzz
		 * @version 1.0
		 * @date 2014-7-2
	     */
	    triggerEvent:function(method) {
	    	return this.trigger.apply(this, Array.prototype.slice.call(arguments));
	    },
	    /**
	     * 激活事件.
	     * @name trigger
	     * @param {string} method 事件名
	     * @param {object} params 参数
	     * @example
	     *    //绑定事件
	     *    grid.bind("click", function(ent, key) {
	     *        if(key == 13) {
	     *            alert(key);
	     *        }
	     *    })
	     *    //激活事件
	     *    grid.trigger("click", [ent, key]);
		 * @author qzz
		 * @version 1.0
		 * @date 2014-7-2
	     */
	    trigger:function(method) {
			var cent = this._events[method];
	    	if(cent != null) {
	    		var re = null;
	    		for(var i = 0, len = cent.length; i < len; i++) {
	    			var fcObj = cent[i];
	    			if(fcObj != null && typeof fcObj.func == "function") {
	    				var args = arguments[1];
	    				//事件执行
	    				if(fcObj.event != null) {
	    					args.splice(0, 0, fcObj.event);
	    				}
	    				if(fcObj.owner == null) {
	    					fcObj.owner = this;
	    				}
						try {
	    					var cre = fcObj.func.apply(fcObj.owner, args);
						} catch(e) {
	    					this.logInfo(method + " event fire error " + e.message + e.stack);
	    				}
	    				if(cre != null) {
	    					if(re == null) {
	    						re = cre;
	    					} else {
	    						if(re instanceof Array) {
	    							re.push(cre);
	    						} else {
	    						    re = [re];
	    						    re.push(cre);
	    						}
	    					}
	    				}	    				
	    			} else {
	    				//this.logInfo(method + " is not a function");
	    			}
	    		}
	    		return re;
	    	} else {
	    		//this.logInfo(method + " event not found ");
	    	}
	    },
	    /**
	     *日志输出函数 .
	     *@param {String} str 要输出的内容
	     *@param {String} date 日期
	     */
	    logInfo:function(str, date){   
	    	//alert(console);
	    	if(window.console != null) {
	    		if(date == null) {
	    		    date = new Date();
	    		}	    		
	    		var h = date.getHours();
	    		var m = date.getMinutes();
	    		var s = date.getSeconds();
	    		var ms = date.getMilliseconds();
	    		date = null;
	    		var str = "["+h+":"+m+":"+s+"."+ms+"][" + this.index +  ":" + this.className + "]" + str;
	    		if(window.console.logStack == null) {
	    			window.console.logStack = [str];
	    		} else if(window.console.logStack.length < 10) {
	    			window.console.logStack.push(str);
	    		} else {
	    			window.console.logStack.push(str);
	    			var logStr = window.console.logStack.join("\n");
	    			setTimeout(function(){
	    				window.console.info(logStr);	    			    
	    			}, 0);
	    			window.console.logStack = [];
	    		}
	    	}
	    },
	    /**
	     * 时间统计日志(开始).
	     * @param {String} str 要输出的信息
	     */
	    logBegin:function(str) {
	    	this.beginDate = new Date();
	    	this.logInfo("[BEGIN]" + str, this.beginDate);
	    },
	    /**
	     * 时间统计日志(结束).
	     * @param {String} str 要输出的信息
	     */
	    logEnd:function(str) {
	    	if(this.beginDate != null) {
	    		var bh = this.beginDate.getHours();
	    		var bm = this.beginDate.getMinutes();
	    		var bs = this.beginDate.getSeconds();
	    		var bms = this.beginDate.getMilliseconds();
	    		var date = new Date();
	    		var eh = date.getHours() - bh;
	    		var em = date.getMinutes() - bm;
	    		if(em < 0) {
	    			eh --;
	    			em += 60;
	    		}
	    		var es = date.getSeconds() - bs;
	    		if(es < 0) {
	    			em --;
	    			es += 60;
	    		}
	    		var ems = date.getMilliseconds() - bms;
	    		if(ems < 0) {
	    			es --;
	    			ems += 1000;
	    		}
	    		date = null;
	    		var times = (eh * 3600 + em * 60 + es) * 1000 + ems;
	    		this.logInfo("[END]" + str + this._i18n.qzz.useTime.replace("{0}",times));
	    	}
	    },
	    /**
	     * 获取当前浏览器类型.
	     * <p>
	     * 	如果当前浏览器为IE系列，则返回 "IE" ，<br>
	     *  如果是其他浏览器则返回 ""
	     * </p>
	     */
	    getBrowser:function(type) {
	    	if(type == null) {
	    		type = "msie";
	    	}
	    	var version = window.navigator.appVersion;
	    	if(typeof version == "string") {
	    		version = version.toLowerCase();
	    	}
	    	if(version != null && version.indexOf(type) >= 0) {
	    		return true;
	    	} else {
	    		if(type === "msie" && version != null && /(msie\s|trident.*rv:)([\w.]+)/.test(version)) {
	    			return true;
	    		}
	    		return false;	
	    	}	    	
	    },
	    /**
	     * 字符串截取.
	     * @param str 字符串
	     * @param length 长度
	     * @return 返回字符串
	     */
	    subStr:function(str, length) {
	    	var v = str; 
	    	var len = 0;
	    	var i = 0;
	    	for(; i<v.length; i++) {
	           if(v.charCodeAt(i)>256) {
	        	   if(len + 2 <= length) {
	                   len   +=   2;
	        	   } else {
	        		   break;
	        	   }
	           } else if(len + 1 <= length){
	               len++;
	           } else {
	        	   break;
	           }
	        }
	        return str.substring(0, i);
	    },
	    /**
	     * 字符串长度.
	     * @param str 字符串
	     */
	    strLen:function(str) {
	    	//modify by yinshanpeng on 2014.11.8 ，处理当str为number类型时，报错的问题F639312
//	    	if(typeof(str) === "number") {
//	    		return (str + "").len();
//	    	} else if(typeof(str) === "string") {
//	    		return str.len();
//	    	}
	    	///*
	    	var v = str;
	        var len = 0;     
	    	for(var i=0; i<v.length; i++) {
	           if(v.charCodeAt(i)>256) {
	               len   +=   2;
	           } else {
	               len++;
	           }
	        }
	    	v = null;
	    	i = null;
	        return len;
	        //*/
	    },
	    /**
	     * 获取数据源
         * @return {DataSource} 数据源
	     */
	    getDataSource:function() {
	    	//if(this.dataSource == null 
	    	//		&& ecp != null && ecp.model != null && ecp.model.DataSource != null) {
	    	//	this.dataSource = new ecp.model.DataSource();
	    	//}
	    	return this.dataSource;
	    },
	    /**
	     * 设置数据源
	     * @param {DataSource} ds 数据源
	     */
	    setDataSource:function(ds) {
	    	this.dataSource = ds;
	    },
	    /**
	     * 是否为新的元数据类型.
	     * @returns {Boolean}
	     */
	    isNewByMeta: function(){
			return this.newByMeta;
		},
		/**
		 * 设置新的元数据类型.
		 * @param {Boolean} b
		 */
		setNewByMeta: function(b){
			this.newByMeta = b;
		},
		/**
		 * 是否为空. 
		 * @see this.isNotEmpty
		 * @param {Object} value 判断的值
		 * @param {String} path 层级关系
		 * @returns {Boolean}
		 */
		isEmpty:function(value, path) {
			//return (value == null || value === "");
			return !this.isNotEmpty(value, path);
		}, 
		/**
		 * 是否不为空.
		 * @param {Object} value 判断的值
		 * @param {String} path 层级关系
		 * @returns {Boolean}
		 */
		isNotEmpty:function(value, path) {
			var re = true;
			if(value == null || value === "") {
			    re = false;
			} else if(typeof value === "object") {
				if(value instanceof Array) {
					re = value.length > 0;
				} else {
					re = false;
					for(var key in value) {
						re = true;
						break;
					}
				}
			}
			return re;
		},
		/**
		 * 合并json对象.
		 */
		extend:function(base, opt) {
        	if(base == undefined ) {
        		return opt;
        	}
            for (var i in opt) {
                if (typeof opt[i] == "object") {
                    if (!base[i]) {
                        base[i] = {};
                    }
                    arguments.callee(base[i], opt[i]);
                } else {
                    base[i] = opt[i];
                }
            }
            return base;
		},
		hz2py:function(value) {
			if(this.hasbind("onHz2py")) {
				value = this.trigger("onHz2py",[value]);
		    } else if($.hz2py != null) {
			    value = $.hz2py.transToPinYin(value);
			}
			return value;
		},	
		
		/**
		 * 字符串、数字大小比较
		 * <p>
		 *	 1.参数1 或 参数2 中任意一个类型为“object”时，返回 -1
		 *	 2.大于返回数值 1 ，等于返回数值 0 ，小于返回数值 -1
		 * </p>
		 * @param {String | Number} a
		 * @param {String | Number} b
		 * @retrun {Number}
		 * @author yinshanpeng@ygsoft.com
		 * @date 2014.12.03
		 */
		compare : function(a ,b, cashJson) {
			var apy = bpy = null;
    		if(typeof(a) === "object" || typeof(b) === "object") {
				return -1;
			} else if(this.isNumber(a) && this.isNumber(b)) {
			 	return a-b > 0 ? 1 : (a===b ? 0 : -1);
			//} else if(this.isDate(a) && this.isDate(b)) {
				
			} else {
				if(cashJson != null) {
					apy = cashJson[a];
					if(apy == null) {
					    apy = this.hz2py(a);
					    cashJson[a] = apy;
					}
					bpy = cashJson[b];
					if(bpy == null) {
					    bpy = this.hz2py(b);
					    cashJson[b] = bpy;
					}					
				} else {
					apy = this.hz2py(a);					
					bpy = this.hz2py(b);
					if(cashJson != null) {
						cashJson[a] = apy;
						cashJson[b] = bpy;
					}					
				}
				return apy.localeCompare(bpy);
			}
		},
		/**
		 * 数值型添加千分符.
		 * @param {Number} value 数值
		 * @returns {String}
		 */
        numberFormat:function(value) {			
			var vlAry = (value + "").split(".");
			vlAry[0] = vlAry[0].replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, "$1,");
	        return vlAry.join("."); 
	    },
		/**
		 * 返回类名.
		 * @returns {String}
		 */
		getEcpType:function() {
			return this.className;
		},
		/**
		 * 返回属性对象.
		 * @return {Object}
		 */
		getOption:function() {
			return this.option;
		},
		/**
		 * 返回默认属性对象(空对象).
		 * 
		 * @returns {Object}
		 */
		getDefaultOption:function() {
			return {};
		},
		/**
		 * 返回控件名称.
		 * @returns {String} 控件名称
		 */
		getName:function() {
			return this.getOption().name;
			//return this.name;
		},
		/**
		 * 设置控件名称.
		 * @param {string} name 要设置的名称
		 */
		setName:function(name) {
			//this.name = name;
			this.getOption().name = name;
		},
		getBooleanValue:function(value, def) {
			return this._getBooleanValue(value, def);
		},
		getJsonValue:function(val1, val2, def) {
			if(val1 != null) {
				return val1;
			} else if(val2 != null) {
				return val2;
			} else {
				return def;
			}
		},
		_asynRun:function(func, args, times) {
			if(times == null && typeof args == "number") {
				times = args;
				args = [];
			}
			if(typeof func === "function") {
				var _this = this;
				setTimeout(function(){func.apply(_this, args);}, times);
			}
		},
		/**
		 * 获取布尔类型.
		 * 
		 * @param {Object} value 传入的值(任何类型)
		 * @param {Boolean} def 缺省值(当value不足以满足转换为Boolean的情况下，返回该值)
		 * @returns {Boolean}
		 */
		_getBooleanValue:function(value, def) {
			if(typeof value == "boolean") {
				return value;
			} else if(typeof value == "string") {
				//处理各种布尔情况
				value = value.toUpperCase();
				return value === "TRUE" 
					      || value === "YES"
					    	  || value === "Y"
					              || (!isNaN(value) && value !== "0");
			} else if(typeof value == "number") {
				return value != 0;
			} else if(typeof value == "date") {
				return false;
			} else if(typeof def == "boolean") {				
			    return def;
			} else {
				return false;
			}
		},
		isNumber : function(prm) {
			if(typeof prm === "number") {
				return true;
			} else if (typeof prm === "string") {
				return /^[0-9]+(.[0-9]*)$/.test(prm);
			} else {
				return false;
			}
		},
		/**
		 * 比较字符串.
		 * @param {string} str1 字符串1
		 * @param {string} str2 字符串1
		 * @param {json} casch 缓存
		 * @return {number} 返回比较结果
		 */
		compare:function(str1, str2, casch, dataType) {
			if(dataType != null && dataType === "string") {
				str1 = "s" + str1;
				str2 = "s" + str2;
			}
			var a = str1, b = str2, cashJson = casch;
			var apy = bpy = null;
    		if(typeof(a) === "object" || typeof(b) === "object") {
				return -1;
			} else if(this.isNumber(a) && this.isNumber(b)) {
			 	return a-b > 0 ? 1 : (a===b ? 0 : -1);
			} else {
				if(cashJson != null) {
					apy = cashJson[a];
					if(apy == null) {
						apy = this.hz2py(a);
						cashJson[a] = apy;
					}
					bpy = cashJson[b];
					if(bpy == null) {
					    bpy = this.hz2py(b);
					    cashJson[b] = bpy;
					}					
				} else {
					apy = this.hz2py(a);					
					bpy = this.hz2py(b);
					if(cashJson != null) {
						cashJson[a] = apy;
						cashJson[b] = bpy;
					}					
				}
				return apy.localeCompare(bpy);
			}
		},
		/**
		 * 中文大小写转换.
		 * @par
		 */
		numUpper:function(value, stype) {
			if(this._i18n.en_us) {
				return value;
			}
			var re = value;
			if(typeof re == "string") {
				re = re.replace(/,| /g, "");
				if(isNaN(re)) {
					return value;
				}
			} else {
				re = re + "";
			}
			if(stype == "Lower" || stype == "Upper" || stype == "MoneyLower" || stype == "MoneyUpper") {
				var num = {"Lower":this._i18n.qzz.nlower,
					       "Upper":this._i18n.qzz.nupper			   
				           }
				var unit = {"Lower":this._i18n.qzz.ulower,
						    "Upper":this._i18n.qzz.uupper,
						    "MoneyLower":this._i18n.qzz.umoneylower,
					        "MoneyUpper":this._i18n.qzz.umoneyupper                       
				           }
				var cnum = num[stype];
				var dic = 1;
		        if(cnum == null) {
		             cnum = num[stype.replace(/Money/, "")];
		             dic = 0;
		        }
				var cunit = unit[stype];				
				var vAry = re.split(".");
				var zv = vAry[0];
				var zdx = "", pv = "", maxu = ""; 
				var ui = 4;
		        var hasv = false;
		        var len = zv.length;
		        var isminus = false;
		        var zi = 0;
		        for(var i = 0; i < len - dic; i++) {
		        	var cv = zv.charAt(i);
		        	if(i == 0 && cv == "-") {
		        		isminus = true;
		        		zi++;
		        	} else if(cv === 0 || cv === "0") {
		        		zi++
		        	} else {
		        		break;
		        	}
		        }
		        if(isminus === false && zi > 0 || isminus === true && zi > 1) {
		        	zv = zv.substr(zi, len);
		        	if(isminus) {
		        		zv = "-" + zv;
		        	}
		        	len = zv.length;
		        }
				for(var i = len - 1; i >= 0; i--) {			
					var cv = zv.charAt(i);
					if(cv == "-") {
						zdx = this._i18n.qzz.minus + zdx;
					} else {
						cv = parseInt(cv, 10);
						var dv = cnum[cv]; 
						if(cv > 0) {
		                     if(maxu !== "") {
		                    	 if(ui != 8 && ui != 12 && ui != 16 && ui != 20) {
		                             zdx = maxu + zdx;
		                         }
		                         maxu = "";
		                     }
		                     if((ui == 5 || ui == 9 || ui == 13 || ui == 17 || ui == 21) && (i == 0 || i == 1 && zv.charAt(i - 1) == "-")) {
		                         zdx = cunit[ui] + zdx;
		                     } else {
							     zdx = dv + cunit[ui] + zdx;
		                     }
		                     hasv = true;
						} else if(pv > 0) {
							 zdx = cnum[0] + zdx;
						} else if(pv === "") {
		                     zdx = cnum[0] + cunit[ui];
		                } else if(ui == 8 || ui == 12 || ui == 16 || ui == 20) {
		                      maxu = cunit[ui];
		                }
						pv = cv;
						ui++;
					}
				}//for i	
				
				if(vAry.length > 1) {
					xv = vAry[1];
					zi = 0;
					len = xv.length;
					for(var i = len - 1; i >= 0; i--) {
						var cv = xv.charAt(i);
						if(cv === 0 || cv === "0") {
							zi++;
						} else {
							break;
						}
					}
					if(zi > 0) {
					    xv = xv.substr(0, len - zi);
					    len = xv.length;
					}
					if(xv !== "") {
			            if(stype !== "MoneyUpper" && stype !== "MoneyLower") {
			                zdx = zdx + cunit[3];
			            }
						var ui = 2;
						for(var i = 0; i < len; i++) {
							var cv = xv.charAt(i);				
							cv = parseInt(cv, 10);
							var dv = cnum[cv];
							zdx = zdx + dv + (cunit[ui] || "");
							ui--;
						} //for
					} else if(stype == "MoneyUpper" || stype == "MoneyLower") {
						if(zdx === "") {
							zdx = cnum[0];
						}
						zdx = zdx + cunit[3];
					}
				} else if(stype == "MoneyUpper" || stype == "MoneyLower"){
					if(zdx === "") {
						zdx = cnum[0];
					}
		            zdx = zdx + cunit[3];
		        }
				return zdx;
			} else {
				return value;
			}
		},
		/**
		 * 去除左右边的空格符.
		 * str  字符串
		 */
		trim:function(str) {
			if(str != null && str !== "" && typeof str == "string") {
				str = str.replace(/(^\s*)|(\s*$)/g,"");
			}
			return str;
		},
	    /**
	     * 注析掉当前类.
	     * @ignore
	     */
	    destroy:function() {
			//单例模式的时候，不释放
	    	if(this._notFree != true) {
		    	// 复制静态方法
		    	var that = this;
		    	if(this._lockDestroy) {
		    		setTimeout(function(){that.destroy();}, 1000);
		    	} else {
			    	setTimeout(function(){
			    		if(that != null) {
			    			for(var name in that) {
			    				if(name === "baseprototype") {
			    					that[name] = null;
			    				} else {
				    				if(that[name] != null && typeof that[name] === "object" && typeof that[name].destroy === "function") {
				    					try {
				    					    that[name].destroy();
				    		    		} catch(e) {
				    		    			if(window.console != null) {
				    		    			    window.console.info(name + "[Destroy]Error:" + e.message);
				    		    			}
				    		    		}
				    				}
				    				delete that[name];	
			    				}
			    			}
			    		}
                        that._hasDestroy = true;
			    	}, 5000);
		    	}
	    	}
	    }
	});
	
   //======================================================print.bean===================================================

	//var qzz = window.qzz;
	
	qzz.space("print");
	
    qzz.print.bean = qzz.Class(qzz.object,{
    	
    	_create : function(option){
            this.base();
    	    this.xmlDoc = new printXmlDoc();
    	    this.ReportNode = this.xmlDoc.addNode("Report");
	   	    this.margins = {};
	   	    this.PageSettings = this.ReportNode.addNode("PageSettings");
	   	    this.PageNode = this.ReportNode.addNode("Page");	   	   
	   	    this.pageCount = 1;
	   	    this.printAllTable = false;
	   	    this.landScape = false;
	   	    this.formulaPrint = false;
	   	    this.pxPerMM = 3.93;
	   	    this.utils = utils;
	   	    
	   	    //宽度、高度			
			this.pswidth = 210;
			this.psheight = 297;
		    var cZoomValue = 1;
		    this.heightScale = 1.65;
		    this.widthScale = 0.75;
			this.maxWidth = parseInt((parseInt(this.pswidth, 10) - 8 - 8) * this.pxPerMM / cZoomValue, 10);
            this.maxHeight = parseInt((parseInt(this.psheight, 10) - 8 - 8) * this.pxPerMM / cZoomValue, 10);
	   	    
	   	    //初始化计算高度对象
	    	this._textSpan = document.createElement("span");  
	    	this._textSpan.style.top = "0px";
	    	this._textSpan.style.left = "100px";
	    	this._textSpan.style.position = "absolute";
	    	this._textSpan.style.borderWidth = "1px";
	    	this._textSpan.style.wordWrap = "break-word";
	    	this._textSpan.style.display = "none";
	    	this._textSpan.style.zIndex = "10000";
	    	if($ == null) {
	            document.body.appendChild(this._textSpan);	    	
	    	} else {	    	
	    	    $("body")[0].appendChild(this._textSpan);
	    	}
		},
		reset : function() {
			this.xmlDoc.setEmpty();
			this.ReportNode = this.xmlDoc.addNode("Report");
	   	    this.margins = {};
	   	    this.PageSettings = this.ReportNode.addNode("PageSettings");
	   	    this.PageNode = this.ReportNode.addNode("Page");
		},
		/**
		 * 把页面模板添加上来.
		 */
		addPageNode : function(pageNode) {
			this.ReportNode.delNode("Page");
			this.PageNode = this.ReportNode.addNode(pageNode);
		},
		_getFormatStr : function(value, formatStr) {
			var formatStyle = formatStr;
			if(formatStyle != null && formatStyle !== "") {
				var res = "";
				var ods = value + "";
				var vlen = ods.length;
				var si = 0, slen = formatStyle.length
				for(; si < slen && si < vlen; si++) {
					var cat = formatStyle.charAt(si);
					if(cat === "#") {
						res += ods.charAt(si);
					} else {
						res += cat;
					}
				}
				for(; si < vlen; si++) {
					res += ods.charAt(si);					
				}
				return res;
			} else {
				return value;				
			}
		},
		/**
		 * 获取text函数.
		 */
		_getText : function(dom) {
			var re;
			if(typeof dom.html === "function") {
				re = dom.html();
			} else {
				re = dom.innerHTML;
			}
			var res = {"&lt;":"<", "&gt;":">","&nbsp;":" "};
			re = re.replace(/<([^<>]+)>|&([a-z]+)(;)?/g, function(key, $1, $2) {
	    	       var key = res[key];
	    	       if(key == null) {
	    	           key = "";
	    	       }
	    	       return key;
	    	});
			return re;
		},
	    _getTdWidth:function(tdNode){
	    	if(tdNode.name == "Td") {
	    		var cws = tdNode.pNode.pNode.getAttrib("TdWidths");
	    		var cwAry = cws;
	    		if(typeof cwAry == "string") {
	    		    cwAry = cwAry.split(",");
	    		}
				var si = tdNode.index;
				var sw = parseInt(cwAry[si]);
				var csp = tdNode.getAttrib("ColSpan");
				if(csp != null) {
					csp = parseInt(csp);
					for(var i = si + 1, len = cwAry.length; i <len && i < si + csp; i++) {
						sw += parseInt(cwAry[i]);
					}
				}
				cwAry = null;
	    		return sw;    		
	    	}
	    	return 0;
	    },
	    /**
	     * 获取文字的像素宽.
	     * @return 返回宽度
	     */
	    _getTextWidth:function(str, size, weight, family) {     
	    	this._textSpan.style.display = "";
	    	this._textSpan.style.width = "";
            if(size != null) {
            	this._textSpan.style.fontSize = size;
            }
            //字体样式
            if(weight != null) {
            	this._textSpan.style.fontWeight = weight;
            }
            if(family != null) {
            	this._textSpan.style.fontFamily = family;   
            }            
            this._textSpan.innerHTML = str;
            var rs = this._textSpan.offsetWidth;
            this._textSpan.style.display = "none";
            return rs;
	    },
	    /**
	     * 获取文字的像素宽.
	     * @return 返回宽度
	     */
	    _getTextHeight:function(str, width, size, weight, family) {
	    	//宋体
	    	//每个字占用的宽度 	     
	    	var sizew = this.widthScale;
	    	//每个字占用的行高
	    	var sizeh = this.heightScale;
	    	
	    	var sl = this.strLen(str);
	    	var key = sl + "@" + width + "@" + size;// + "@" + weight + "@" + family;
            if(this._textHeightJson == null) {
            	this._textHeightJson = {};
            }
            var rs = this._textHeightJson[key];
            if(rs == null) {
            	size = parseInt(size, 10);
                width = parseInt(width, 10);
	            var rownums = width/(size * sizew);
	            var rowcount = sl/rownums;
	            var rt = parseInt(rowcount, 10);
	            if(rowcount > rt) {
	            	rt++;
	            }
	            if(rt > 1) {
	            	rt++;
	            }
	            var rowheight = (sizeh * size) * rt;
	            rs = rowheight;
	            this._textHeightJson[key] = rs;
            }
	        return rs;
	    },
		/**
		 * 获取jggrid表格的表头.
		 * @param {object} grid 表格对象
		 */
		_getGridHeader:function(grid) {
			var headerTab = grid.getControl()[0].grid.hDiv.childNodes[0].childNodes[0];
			var header = [];
			if(headerTab != null && headerTab.tagName == "TABLE") {
			    var rlen = headerTab.rows.length;
			    var bi = 0;
			    for(var i = bi; i < rlen; i++) {
			    	var rows = headerTab.rows[i];
			    	var cls = $(rows).attr("class");
			    	if(cls === "jqg-first-row-header") {
			    		bi++;
			    		continue;
			    	}
			    	var rh = [];
			    	var cindex = 0;
			    	for(j = 0, clen = rows.cells.length; j < clen; j++) {
				    	var cells = rows.cells[j];
				    	var id = $(cells).attr("id");
				    	if(cells.style.display !== "none" && (typeof id != "string" || id.indexOf("_cb") < 0)) {
				    		var colspan = cells.colSpan || cells.colspan || 1;
				    		colspan = parseInt(colspan, 10);
				    		var rowspan = cells.rowSpan || cells.rowspan || 1;
				    		rowspan = parseInt(rowspan, 10);
				    		ctindex = cindex + colspan - 1;
				    		var region = {
				    				colFrom: cindex,
				    				colTo: cindex + colspan - 1,
				    				dataType: "",
				    				rowFrom: i - bi,
				    				rowTo: i + rowspan - 1 - bi,
				    				style: "head",
				    				text: this._getText(cells)
				    		};
				    		rh.push(region);
				    		cindex += colspan;
			    		}
			    	}
			    	header.push(rh);
			    }
			}
			return header;
		},
		/**
		 * 打印页面设置.
		 * @param {JSON} params 参数
		 * @param {JSON} params.Paper 纸张
		 * @param {String} params.Paper.Type 类型  Custom:自定义, A4等
		 * @param {number} params.Paper.Width 类型  Type是Custom时，纸张的宽度
		 * @param {number} params.Paper.Height 类型  Type是Custom时，纸张的高度
		 * @param {JSON} params.Margins 边距 单位mm
		 * @param {number} params.Margins.Top 顶边距
		 * @param {number} params.Margins.Bottom 底边距
		 * @param {number} params.Margins.Left 左边距
		 * @param {number} params.Margins.Right 右边距
		 * @param {number} params.Copies 打印份数 默认为1份
		 * @param {string} params.PageCount 打印页码, 默认全打 
		 *                 ALL: 全打
		 *                 i:打印第i页
		 *                 i-j: 打印i页到j页
		 * @param {boolean} params.LandScape 是否横向 true ，默认为 false
		 * @param {number} params.ZoomValue 缩放系数 整数 如 x 表示 x%
		 * @param {number} params.TextModel 文本打印模式，文本过长时分三种模式打印 
		 *                  0：直接截取，1：缩小显示，2：换行显示, 默认为2：换行显示
		 * @param {boolean} ShowSysWin 显示系统窗口                  
		 * @param {boolean} initDef 是否初始化默认值
		 */
		setPageSettings : function(params, initDef) {
			if(initDef == null) {
				initDef = true;
			}
			if(params == null) {
				params = {};
			}
			//打印纸张
			var paper = params.paper || params.Paper;
			if(initDef && paper == null) {
				paper = {type:"A4"};
			}
			if(paper != null) {
				var type = paper.type || paper.Type;
				if(type == "Custom" || type == "custom") {
				   this.setPaperSize("Custom", paper.width || paper.Width,
						   paper.height || paper.Height);
				} else {
					this.setPaperSize(type);
				}
			}
			//边距
			var margins = params.margins || params.Margins;
			var top, left, right, bottom;
			if(margins != null) {
				top = margins.Top || margins.top;
				left = margins.Left || margins.left;
				bottom = margins.Bottom || margins.bottom;
				right = margins.Right || margins.right;
			}
			if(initDef) {
				if(top == null) {
					top = 8;
				}
				if(left == null) {
					left = 8;
				}
				if(bottom == null) {
					bottom = 8;
				}
				if(right == null) {
					right = 8;
				}
				this.setMargins(top, left, bottom, right);
			}
			//打印缩放
			var zoomValue = params.zoomValue || params.ZoomValue;
			if(zoomValue != null) {
				if(typeof zoomValue == "string") {
					zoomValue = zoomValue.replace("%", "");
				}
			    this.setZoomValue(zoomValue);
			}
			//打印方向
			var lsc = params.landScape == true 
			            ||  params.landScape == "true"
			                || params.LandScape == true
			                    || params.LandScape == "true";
			this.setLandscape(lsc);
			if(top != null && left != null && right != null && bottom != null) {	
				//宽度、高度
				if(lsc) {
					this.pswidth = paper.width || paper.Width || 297;
				    this.psheight = paper.height || paper.Height ||210;
				} else {
				    this.pswidth = paper.width || paper.Width ||210;
				    this.psheight = paper.height || paper.Height || 297;
				}
			    var cZoomValue = 1;
			    if(zoomValue != null && zoomValue !== "") {
					cZoomValue = parseInt(zoomValue, 10)/100;
				}
				this.maxWidth = parseInt((parseInt(this.pswidth, 10) - parseInt(left, 10) - parseInt(right, 10)) * this.pxPerMM / cZoomValue, 10);
	            this.maxHeight = parseInt((parseInt(this.psheight, 10) - parseInt(top, 10) - parseInt(bottom, 10)) * this.pxPerMM / cZoomValue, 10);
			}

			//打印份数
			var copies = params.Copies || params.copies;
			if(initDef && params.Copies == null) {
				copies = 1;
			}
			if(copies != null) {
			    this.setCopies(copies);
			}
			//打印页码
			var pc = params.pageCount || params.PageCount;
			if(pc == "ALL" || initDef && (pc == null || pc === "")) {
				this.printAllPage();
			} else {
				var pcAry = (pc+"").split("-");
				var f, t;
				if(pcAry.length == 1 && pcAry[0] != null) {
					f = pcAry[0];
					t = f;
				} else if(pcAry.length == 2) {
					if(pcAry[0] != null) {
					    f = pcAry[0];
					}
					if(pcAry[1] != null) {
					    t = pcAry[1];
					}
				}
				if(f != null) {
				    this.printSomePage(f, t);
				} else if(initDef){
					this.printAllPage();
				}
			}

			//打印方式
			var tableFillModel = params.textModel || params.TextModel;
			var sowSysWin = params.ShowSysWin;
			if(sowSysWin == null) {
				sowSysWin = params.showSysWin;
			}			
			if(sowSysWin == false) {
			    this.setPrintStyle(2, true, tableFillModel, 0);
	        } else {
	        	this.setPrintStyle(2, true, tableFillModel, 1);	        	
	        }
			this.setOffsetPoint(8, 13);
	        //打印状态
	        var date = new Date();
	        this.option.hasPrintState = date.getTime();
	        this.option.hasPrint = 1;
			this.option.barcode = {};
		},
		setNoWorkFlow:function(value) {
			if(value == null || value === "") {
				value = true;
			}
			this.PageNode.setAttrib("NoWorkFlow", value);
		},
		setWorkFlowWidth:function(value) {
			if(value == null || value === "") {
				value = 800;
			} else {
				if(value > this.maxWidth) {
					value = this.maxWidth;
				}
			    this.PageNode.setAttrib("WorkFlowWidth", value);
			}
		},
		setWorkFlowFontSize:function(value) {
			if(value == null || value === "") {
				value = 9;
			}
			this.PageNode.setAttrib("WorkFlowFontSize", value);
		},
		setCopies : function(count) {
			if(count == null || count == null || count === "" || isNaN(count)) {
			    count = 1;	
			}			
			this.pageCount = count;
			//添加打印份数控制
			var pp = this.PageSettings.getNode("PrintRange");
			if(pp == null) {
			    pp = this.PageSettings.addNode("PrintRange");
			}
			pp.setAttrib("Copies", count);
		},
		//设置Report属性.
		setPrintStyle : function(PrintControllerStyle, IsRepeatHeader, tableFillModel, useDefPrinter) {
			this.ReportNode.setAttrib("PrintControllerStyle", PrintControllerStyle);
			this.ReportNode.setAttrib("IsRepeatHeader", IsRepeatHeader);
			this.ReportNode.setAttrib("TableBodyFillMode", tableFillModel);
			if(useDefPrinter != null && useDefPrinter !== 0) {
				useDefPrinter = 1;
			}
			this.ReportNode.setAttrib("UseDefPrinter", useDefPrinter);			
		},
		/**
		 * 设置是否横向打印.
		 */
		setLandscape : function(value) {
			this.PageSettings.addNode("Landscape", value);
			if(typeof value == "string") {
				value = Boolean(value);
			}
			this.landScape = value;
		},
		setPaperSize : function(value, width, height) {
			var psiNode = this.PageSettings.addNode("PaperSize");
			psiNode.addNode("PaperKind", value);
			if(width != null) {
				psiNode.addNode("PaperWidth", width);
			}
			if(height != null) {
				psiNode.addNode("PaperHeight", height);
			}
			psiNode = null;
		},
		setMargins : function(top, left, bottom, right) {
			var mgNode = this.PageSettings.addNode("Margins");
			if(top != null) {
			    mgNode.setAttrib("Top", top);
			}
			if(left != null) {
			    mgNode.setAttrib("Left", left);
			}
			if(right != null) {
			    mgNode.setAttrib("Right", right);
			}
			if(bottom != null) {
			    mgNode.setAttrib("Bottom", bottom);
			}
			mgNode = null;
		},
		printAllPage : function() {
			var pp = this.PageSettings.getNode("PrintRange");
			if(pp == null) {
			    pp = this.PageSettings.addNode("PrintRange");
			}			
			pp.setAttrib("Name", "AllPages");
		},
		printSomePage : function(fromPage, toPage) {
			var pp = this.PageSettings.getNode("PrintRange");
			if(pp == null) {
			    pp = this.PageSettings.addNode("PrintRange");
			}	
			//页数类型
			pp.setAttrib("Name", "SomePages");
			pp.setAttrib("FromPage", fromPage);
			pp.setAttrib("ToPage", toPage);
		},
		setOffsetPoint : function(X, Y) {
			var op = this.PageSettings.addNode("OffsetPoint");
			op.setAttrib({"X":X,"Y":Y});
			op = null;
		},
		/**
		 * 添加文本显示.
		 * text 文本内容
		 * @param {JSON} option 对应属性 
		 * @param {number} option.top 顶点,
		 * @param {number} option.left:左边,
		 * @param {number} option.width:宽度,
		 * @param {number} option.height:高度,
		 * @param {number} option.fontSize:字号,
		 * @param {string} option.align:横对齐,Left, Center, Right
		 * @param {string} option.lineAlign:纵对刘,Top, Center, Bottom
		 * @param {number} option.id:id 值
		 * @param {boolean} option.I 是否斜体
		 * @param {boolean} option.B 是否粗体
		 * @param {boolean} option.U 是否有下画线
		 * @param {boolean} option.S 是否删除线
		 * @param {string} option.relative 是否相对打印
		 */
		addText : function(text, option) {
			 var txtNode = this.PageNode.addNode("Text", text, option.id);
			 var fontSize = option.fontSize || option.FontSize || 11;
			 var width = option.width || option.Width;
			 if(width == null) {
				 width = fontSize * this.widthScale;
			 } else if(width == "100%") {
				 width = this.maxWidth;
			 }
			 var height = option.height || option.Height;
			 if(height == null) {
				 height = fontSize * this.heightScale;
			 }
			 txtNode.setAttrib({"X":option.left || option.Left || 0,
				                "Y":option.top || option.Top || 0,
				                "FontSize":fontSize,
				                "FontName":option.fontName || option.FontName || this._i18n.qzz.defFontFamily,
		                        "Width":width, 
		                        "Height":height,
		                        "Color":option.color || option.Color || "#000000",
		                        "I":option.I || false,
		                        "B":option.B || false,
		                        "U":option.U || false,
		                        "S":option.S || false,
		                        "Alignment":option.align || option.Align || "Center",
		                        "LineAlignment":option.lineAlign || option.LineAlign || "Center",
		                        "Lock":option.lock || option.Lock ||"",
		                        "RelativeTableID":option.relative || "1"});
			 return txtNode;
		},
		setImage : function(imgNode, url, top, left, width, height) {
			if(imgNode != null) {
				imgNode.setAttrib({"X":left,"Y":top});
				if(height != null) {
					imgNode.setAttrib("Height", height);
				}
				if(width != null) {
					imgNode.setAttrib("Width", width);
				}
				url = this._transFullUrl(url);
				var vln = imgNode.getNode("Value");
				vln.setValue(url);
			}
		},
		_transFullUrl : function(url) {
			if(!(/[a-zA-Z]:|[hH][tT][tT][pP]:/.test(url))) {
				if(this.location == null) {
					this.location = window.location.protocol + "//" + window.location.host;
				}
				if(url.charAt(0) !== "/") {
					url = "/" + url;
				}
				url = this.location + url;
			}
			return url;
		},
		_getLocation:function(){
			if(this.location == null) {
				this.location = window.location.protocol + "//" + window.location.host;
			}
			return this.location
		},
		_getPrintOption : function(po, key, def) {
			if(typeof key == "string") {
				key = [key];
			}
			var re = def;
			if(po.optionEnable == null || po.optionEnable == true || po.optionEnable === "true") {
				for(var i = 0, len = key.length; i < len; i++) {
					var vl = po[key[i]];
					if(vl != null && vl !== "") {
						re = vl;
						break;
					}
				}
			}
			return re;
		},
		/**
		 * 添加图片.
		 * @param {string} url 路径
		 * @param {number} top 顶点
		 * @param {number} left 左点
		 * @param {number} width 宽
		 * @param {number} height 高
		 * @param {NODE} pNode 父节点
		 */
		addImage : function(url, top, left, width, height, pNode) {
			if(pNode == null) {
				pNode = this.PageNode;
			}
			var imgNode = pNode.addNode("Img");
			imgNode.setAttrib({"X":left,"Y":top});
			if(height != null) {
				imgNode.setAttrib("Height", height);
			}
			if(width != null) {
				imgNode.setAttrib("Width", width);
			}
			url = this._transFullUrl(url);
			imgNode.addNode("Value", url);
			return imgNode;
		},

		/**
		 * 添加画线.
		 * @param {string} text 文本显示
		 * @param {JSON} option 参数对象
		 * @param {number} option.top 顶点
		 * @param {number} option.left 左点
		 * @param {number} option.width 宽
		 * @param {number} option.height 高
		 * @param {string} option.border 线
		 * @param {string} option.color 颜色
		 * @param {string} option.id id值
		 */
		addLine : function(text, option) {
			if(option == null) {
				option = {};
			}
			var lineNode = this.PageNode.addNode("Line", text, this.getJsonValue(option.id, option.Id));
			var width = this.getJsonValue(option.width, option.Width);
			if(width == null) {
				width = 300;
			} else if(width == "100%") {
				width = this.maxWidth;
			}
			var height = this.getJsonValue(option.height,option.Height);
			if(height == null) {
				height = 300;
			} else if(height == "100%") {
				height = this.maxHeight;
			}
			lineNode.setAttrib({"Y": this.getJsonValue(option.top, option.Top, 0), 
				                "X": this.getJsonValue(option.left, option.Left, 0),
				                "Width": width,
				                "Height": height,
				                "Border": this.getJsonValue(option.border, option.Border),
				                "Style": this.getJsonValue(option.style, option.Style, "dashed"),
				                "Color": this.getJsonValue(option.color, option.Color),
				                "Lock": this.getJsonValue(option.lock, option.Lock)
				                });
			return lineNode;
		},
		/**
		 * 添加整个表格控件数据.
		 * @param {grid} dataGrid 表格控件
		 */
		addGridModel:function(dataGrid) {
			var p = dataGrid.control[0].p;
			var dgid = p.id;
			//获取表头
			var header = [];
			if(dataGrid.isComponent) {
				header = dataGrid.getHeader(null, dataGrid.getOption().rownumbers);
			} else {
				header = this._getGridHeader(dataGrid);
			}
			var hlen = header.length;
			var fontSize = 9;
			if(dataGrid.getOption().fontSize != null && dataGrid.getOption().fontSize !== "") {
				fontSize = dataGrid.getOption().fontSize;
			}
			var rc = 0;
			for(var j = hlen - 1; j >= 0; j--) {
				if(header[j].length > 0) {
					rc ++;
				}
			}
			if(rc == 0) return null;
			var hrs = "0";
			for(var i = 1; i < hlen; i++) {
				hrs += "," + i;
			}
			//获取相对位置
			var rly = 5;
			if(dataGrid.getOption().relativeY != null) {
				rly = dataGrid.getOption().relativeY;
			}
			var po = dataGrid.getControl().attr("printOption");
			if(po != null && po !== "") {
				po = JSON.parse(po);
			} else {
				po = {};
			}
			fontSize = this._getPrintOption(po, ["fontSize", "FontSize", "fontsize"], fontSize);
			rly = this._getPrintOption(po, ["Top","top"], rly);
			var cms = p.colModel;
            //开始打印表格***
			//过滤掉隐藏列的colModel			
			var colModel = [];
			var tdWidths = [];
			var k = 0;
			var colSum = 0;
			var hasRn = false;
			if(dataGrid.isComponent) {
				cms = dataGrid.getOption().colModels;
                if(dataGrid.getOption().rownumbers) {
			    	colModel.push({align:"Center","caption":this._i18n.qzz.index,"index":"rn","name":"rn", "width":60,"hidden":false,"colIndex":0});
			    	tdWidths[k++] = 60;
			    	colSum = 60;
			    }
			}
			for(var i = 0, len = cms.length; i < len; i++) {
			    var curCm = cms[i];
			    if(curCm.hidden != true && curCm.name != null && curCm.name !== "" && curCm.name != "cb") {	
			    	if(curCm.name === "rn" || dataGrid.getOption().rownumbers != false) {
			    		hasRn = true;
			    	}
				    colModel.push(curCm);
				    //计算宽度
			  	    var cw = curCm.width;				
					if(dataGrid.isComponent) {
						var ocw = dataGrid.getColWidth(curCm.colIndex + 1); 
						if(ocw > 0) {
							cw = ocw;							
						}
					}				
				 	//打印表宽，比实际宽要宽一些，所以加10个像素
				  	tdWidths[k++] = cw + 10; 
				  	colSum += cw + 10;
			    }
			}
			
			//重新计算宽度
			if(colSum > this.maxWidth && k * 20 < this.maxWidth || this.option.autoWidth == true) {
				var ce = this.maxWidth/colSum;
				var nColSum = 0;
				var len = tdWidths.length;
				for(var i = 0; i < len; i++) {
					tdWidths[i] = parseInt(tdWidths[i] * ce, 10);
					nColSum += tdWidths[i];
				}
				ce = this.maxWidth - nColSum;
				for(var i = 0; i < len && ce != 0; i++) {
					if(ce > 0) {
						tdWidths[i] ++;
						ce--;
					} else {
						tdWidths[i] --;
						ce++;
					}
				}
			}			
			var tabNode = this.addTable({top:0, left:0, id:dgid});
			this.setHeadCount(tabNode, hrs, hlen);
			var clen = 0;
			var windex = 0;
			var rowHeight = 25;	
			if(dataGrid.getOption().printRowHeight != null) {
				rowHeight = dataGrid.getOption().printRowHeight;
			} else if(dataGrid.getOption().rowHeight != null) {
				rowHeight = dataGrid.getOption().rowHeight;
			} else if(dataGrid.rowHeight != null) {
				rowHeight = dataGrid.rowHeight;
			}
			//添加固定行数显示
			if(dataGrid.getOption().lessRows != null) {
				tabNode.setAttrib("lessRows", dataGrid.getOption().lessRows);
			}
			var prowheight = [];
			//生成表头
			for(var i = 0; i < hlen; i++) { // hlen 合并多列的列数，
				var ma = 0; //ma是p.colModel 里面的下标。  第二列的时候，ma初始化为0;
				var rowNode = this.addRow(tabNode);	
				var colheader = header[i];
				clen = colheader.length;  // 要打印的列数
				var maxHeight = rowHeight;
				if(hasRn && i > 0) {
					windex = 1;
				}
				for(var j = 0; j < clen; j++) {
					var colSpan, rowSpan;
					var colH = colheader[j];
					if(colH.colTo != colH.colFrom) { 
					    colSpan = colH.colTo - colH.colFrom + 1;
					}
					if(colH.rowTo != colH.rowFrom) {
					    rowSpan = colH.rowTo - colH.rowFrom + 1;
					}
					if(colH.rowspan != null && colH.rowspan > 1) {
						rowSpan = colH.rowspan;
					}
					var text = this.trim(colH.text.replace(/&nbsp;/g, " "));
					this.addCell(rowNode, text, 
					    {"colSpan":colSpan, "rowSpan":rowSpan, "fontSize":fontSize, "align":"Center", "lineAlign":"Center"});					
										
					var ccw = 0;
					for(var ci = colH.colFrom; ci <= colH.colTo; ci++) {
						
						ccw += tdWidths[ci + windex];
					}
					if(ccw > 0) {
						var ch = this._getTextHeight(text, ccw, fontSize);
						//减去上几行所占用的行高
						if(rowSpan != null && rowSpan > 1) {
							ch -= (rowSpan - 1) * rowHeight;
						}
						if(maxHeight < ch) {							
							maxHeight = ch;
						}
					}
					colSpan = null;
					rowSpan = null;
				} //j
				prowheight.push(maxHeight);
				rowNode.setAttrib("Height", maxHeight);
				rowNode = null;
				colheader = null;
			} //i

			var border = this._getPrintOption(po, ["border","Border"], 1);
			//是否显示边线
			if(this.option.formulaPrint || border === 0) {
				this.setNoBorder(tabNode, "true");
			}
			this.option.rowCountPerPage = this._getPrintOption(po, 
					["rowCountPerPage","RowCountPerPage", "rowcountperpage"], this.option.rowCountPerPage);
			//设置每页记录数
			if(this.option.rowCountPerPage > 0) {
				this.setRowCountPerPage(tabNode, this.option.rowCountPerPage);
			}
			//var colModel = dataGrid.getGridParam().colModel;
			var mcount = colModel.length;
			//设置行循环
			var rowNode = this.addRow(tabNode);
			//var gridDataField = dataGrid.getControl().attr("id");
			//if(gridDataField == null) {
			var gridDataField = dataGrid.getName();
			//}
			var dfs = this.setDataFields(rowNode, gridDataField);
			rowNode.setAttrib("Height", rowHeight);
			//设置各个列的dataField
			for(var i = 0; i < mcount; i++) {
				var curCm = colModel[i];
				if(curCm.hidden !== true && curCm.name != null && curCm.name !== "" && curCm.name != "cb") {
			  	    var cellNode = this.addCell(rowNode, "", 
				      {"fontSize":fontSize, "align":dataGrid.getColAlign(curCm.name), "lineAlign":"Center"});
			  	    if(curCm.formatStyle != null && curCm.formatStyle !== "") {
			  	    	cellNode.setAttrib("formatStyle", curCm.formatStyle);
			  	    }
			  	    this.setDataField(cellNode, curCm.name, dfs);			  	    
			  	    cellNode = null;
				}
			}
			dfs = null;
			//合计行处理
			//把合计行属性缓存到table节点的sum属性中.
			if(dataGrid.isComponent) {
				if(dataGrid.getOption().footerrow && !this.option._noAmount) {
					var rowValue = [];					
					rowNode = this.addRow(tabNode);
					gridDataField = dataGrid.getName();
					dfs = this.setDataFields(rowNode, gridDataField);					
					for(var j = 0,mcount = colModel.length; j < mcount; j++) {
						var curCm = colModel[j];
						if(curCm.hidden !== true && curCm.name != null && curCm.name !== "" && curCm.name != "cb") {
					  	    var cellNode = this.addCell(rowNode, "", 
						      {"fontSize":fontSize, "align":dataGrid.getColAlign(curCm.name), "lineAlign":"Center"});
					  	    if(curCm.formatStyle != null && curCm.formatStyle !== "") {
					  	    	cellNode.setAttrib("formatStyle", curCm.formatStyle);
					  	    }
					  	    this.setDataField(cellNode, curCm.name, dfs);
					  	    cellNode = null;
						}
					}
				} //if footerrow
			}
			
			dfs = null;
			var cws = dataGrid.getOption().colWidths;
			cws = this._getPrintOption(po, ["colwidths","colWidths","ColWidths"], cws);
			//设置各列宽
			if(cws != null) {
				var tdws = cws.split(",");
				if(tdws.length < tdWidths.length) {
					for(var i = tdws.length, len = tdWidths.length; i < len; i++) {
						tdws.push(tdWidths[i]);
					}
				}
				if(tdws != null) {
				    this.setCellWidths(tabNode, tdws.join(","));
				} else {
					this.setCellWidths(tabNode, tdWidths.join(","));
				}
			} else {
				this.setCellWidths(tabNode, tdWidths.join(","));
			}
			//设置相对位置
			tabNode.setAttrib({"RelativeY":"true",
					           "RelativeTableID":this.option.curTableId,
					           "Y":rly});
			//计算子表序号
			if(dgid.indexOf("mainTable") < 0) {
				this.option.subGridIndex ++;			
				//子表分页打印，或审批单独打印, 多子表一起打印
				if((this.option.subTableNextPage && !this.option.subGridOnOnePage
						    || this.option.subGridOnOnePage && this.option.subGridIndex < 2)
					        || this.option.printSpInfo && this.option.spPrintType == "1" 
						           && dataGrid.getName() == "shenpiGridprocessExamineIdea"	
				    ) {
					tabNode.setAttrib("PrintInNewPage", "true");
				}
			}
			var lock = this._getPrintOption(po, ["Lock","lock"], lock);
			if(lock !== "") {
			    tabNode.setAttrib("Lock", lock);
			}
			var pinp = this._getPrintOption(po, ["printinnewpage","printInNewPage","PrintInNewPage"], false);
			if(pinp === "true" || pinp === "True" || pinp === true) {
				tabNode.setAttrib("PrintInNewPage", "true");
			}
			header = null;
			hlen = null;
			clen = null;
			tdWidths = null;
			colModel = null;
			mcount = null;
			rowNode = null;
			//tabNode = null;
			return tabNode;
		},
		/**
		 * 按数组打印.
		 * @param {Array} dataAry 二维数据数组
		 * @param {number} fontSize 字体 
		 */
		addArrayTable:function(dataAry, fontSize, top, left, autoWidth, hasNoBorder, colWidths, aligns, headRows) {
			var da = dataAry;
			if(!(da instanceof Array)) {
				da = [da];
			}
			if(da.length == 0) {
				return;
			}
			if(top == null || top === "") {
				top = 0;
			}
			if(left == null || left === "") {
				left = 0;
			}
			if(fontSize == null || fontSize === "") {
				fontSize = 9;
			}
			var rc = da.length;

			var avgW = 100;				
			
			if(this.option._arrayId == null) {
				this.option._arrayId = 0;
			}			
			this.option._arrayId++;
			tabNode = this.addTable({"top":top, "left":left, "id":"ary" + this.option._arrayId});
			
			var tdws = [], fieldNames = [], hrs = [];
			for(var i = 0; i <rc; i++) {
				hrs.push(i);
				var rowNode = this.addRow(tabNode);
				var maxHeight = 24;
				var rowData = da[i];
				if(rowData instanceof Array) {
					var cc = rowData.length;
					if(autoWidth == true && i == 0) {
						if(cc > 0) {
						    avgW = parseInt(this.maxWidth/cc, 10);
						}
					}
					for(var j = 0; j < cc; j++) {
						if(i == 0) {
						    tdws.push(avgW);
						}
						var text = rowData[j] || "";
						var align = "Left";
						if(aligns instanceof Array) {
							align = aligns[j] || align;
						}
						this.addCell(rowNode, text, {"colSpab":1, "rowSpan":1, "fontSize":fontSize, "align":align, "lineAlign":"Center"});
						var cch = this._getTextHeight(text, avgW, fontSize);
						if(cch > maxHeight) {
							maxHeight = cch;
						}
					}
				} else {
					if(i == 0) {
						for(var key in rowData) {
							fieldNames.push(key);
						}
						var cc = fieldNames.length;
						if(autoWidth == true && cc > 0) {
						    avgW = parseInt(this.maxWidth/cc, 10);
						}
					}
					for(var j = 0, len = fieldNames.length; j < len; j++) {
						if(i == 0) {
						    tdws.push(avgW);
						}
						var text = rowData[fieldNames[j]] || "";
						var align = "Left";
						if(aligns instanceof Array) {
							align = aligns[j] || align;
						}
						this.addCell(rowNode, text, {"colSpan":1, "rowSpan":1, "fontSoze":fontSize, "align":align, "lineAlign":"Center"});
						var cch = this._getTextHeight(text, avgW, fontSize);
						if(cch > maxHeight) {
							maxHeight = cch;
						}
					}
				}
				rowNode.setAttrib("Height", maxHeight);
				rowNode = null;
			}
			if(typeof colWidths === "string") {
				colWidths = colWidths.split(",");
			}
			if(colWidths instanceof Array) {
				for(var i = 0, len1 = colWidths.length, len2 = tdws.length; i < len1 && i < len2; i ++) {
					tdws[i] = colWidths[i];
				}
			}
			if(typeof headRows === "string") {
				headRows.split(",");
			}
			if(headRows instanceof Array) {
				hrs = headRows;
			}
			this.setCellWidths(tabNode, tdws.join(","));
			if(hasNoBorder == null) {
				hasNoBorder = "true";
			} else {
				hasNoBorder = hasNoBorder + "";
			}
			this.setNoBorder(tabNode, hasNoBorder);
			this.setHeadCount(tabNode, hrs.join(","), rc);
			tabNode = null;	
		},
		/**
		 * 添加整个表格数据.
		 * @param {JSON} params 参数
		 * @param {number} params.top 顶点
		 * @param {number} params.left 左点
		 * @param {string} params.id
		 * @param {number} params.maxColWidth 单列大最宽度
		 * @param {boolean} params.hasBorder 是否有边线
		 * @param {OBJECT} params.table 表格对象
		 */
		addHTMLTable:function(params) {
			var mtab = params.table;
			if(typeof mtab.attr == "function") {
				mtab = mtab[0];
			}
			var query = params.query || $;
			var tabNode = null;
			if(mtab != null && (mtab.offsetWidth > 0 || $(mtab).attr("colwidths"))) {
				var ml = mtab.rows.length;
				var rindex = 0;
				while (rindex < ml && mtab.rows[rindex].cells.length == 0) {
					rindex ++;
				}
				if (rindex < ml) {
					rows = null;
					var colSum = mtab.offsetWidth;
					var ce = 1;
					if(colSum > this.maxWidth || this.autoWidth == true) {
						ce = this.maxWidth/colSum;
					}
					//ecp平台窗口容器
					var element = $(mtab).closest("[ecpclass='ecp.ui.layout.Window']");
					if(element.length == 0) {
						element = null;
					}
					//设置id
					var tabId = params.id || params.Id || params.ID || mtab.id || mtab.name
					tabNode = this.addTable({"top":params.top, "left":params.left, "id":tabId});
					var fs = mtab.style.fontSize;
					if(mtab.parentElement != null && (fs == null || fs === "")) {
					    fs = mtab.parentElement.style.fontSize;						
					}
					if(fs == null || fs === "") {
						fs = 9;
					}
					if(typeof fs == "string") {
						fs = fs.replace(/px|pt/, "");						
					}
					var tdws = $(mtab).attr("colwidths");
					//解析通用参数
					var po = $(mtab).attr("printOption");
					if(po != null && po !== "") {
						po = JSON.parse(po);
					} else {
						po = {};
					}
					fs = this._getPrintOption(po, ["fontsize","fontSize","FontSize"], fs);
					tdws = this._getPrintOption(po, ["colwidths","colWidths","ColWidths"], tdws);
					if(tdws != null && tdws !== "") {
						tdws = tdws.split(",");
					}
					var left = this._getPrintOption(po, ["left","Left"], params.left);
					if(left != null && left !== 0 && left !== "") {
						tabNode.setAttrib("X", left);
					}
					var top = this._getPrintOption(po, ["left","Left"], params.top);
					if(top != null && top !== 0 && top !== "") {
						tabNode.setAttrib("Y", top);
					}
					//获取列宽数组
					var tdWidths = [];
					var wIndex = 0;
					var colIndex = 0;
					var ignoreRow = 0;
					//保留最多列的行
					var colMxLen = 0;
					var rowMxIndex = 0;
					for(var i = rindex; i < ml; i++) {
						var crow = mtab.rows[i]; //获取TR下面的所有TD
						var clen = crow.cells.length;//获取TD数
						if(clen > 0 && crow.style.display != "none") {
						    //去除隐藏行
							var crHasCell = false;
							for(var j = 0; j < clen; j++) {
								if(crow.cells[j].style.display != "none") {
									crHasCell = true;
									break;
								}
							}
							if(!crHasCell) {
								ignoreRow ++;
								continue;
							}
							//保存多列的行
							if(colMxLen < clen) {
								colMxLen = clen;
								rowMxIndex = i;
							}
							var rowNode = this.addRow(tabNode);
							//默认高度
							var maxHeight = crow.offsetHeight;
							if(maxHeight < 20) {
								maxHeight = $(crow).attr("height");
								if(typeof maxHeight === "string") {
									maxHeight = maxHeight.replace("px", "");
								}
								if(maxHeight == null || maxHeight === "") {
									maxHeight = 20;
								}
							} else if (maxHeight <= 30){
								maxHeight = 24;
							}
							var hasData = false;
							var ccount = 0;
							for(var j = 0; j < clen; j++) {
								var curCell = crow.cells[j];
								var $curCell = $(curCell);
								var html = curCell.innerHTML;
								hasData = hasData || html != null && html.length > 0
								var isImg = /<[iI][mM][gG]/.test(html);								
								var dataField = "";
								var dfAry = html.match(/[dD]ata[fF]ield="([\[\]\w.]+)"/);
								if(dfAry != null && dfAry.length > 0) {
									dataField = dfAry[1];
								}
								var text = this._getText(curCell);
								if(dataField === "" && text === "") {
									var cInput = $curCell.children("input");
									if(cInput.length == 1 && cInput.attr("type") == "text") {
										text = this.trim(cInput.value());
									}
								}								
								if(curCell.style.display == "none") {
									text = "";
									dataField = "";
								}else if(isImg != true){
									//ecp输出控件
									var datafAry=$curCell.find('[ecpclass]');
									if(datafAry.length == 1 && datafAry[0].tagName == "DIV" && datafAry[0].style.display == "none") {
										text = "";
										dataField = "";
									} else {
									    for(var x = 0; x<datafAry.length; x++){	
											var ctrlObj = query.ecp.getUI(datafAry[x], element);
											if(ctrlObj != null) {
												 var ctrl = ctrlObj.textControl || ctrlObj.control;
												 //获取主表单元格中输入控件的值 modify by zxw
												 if(ctrl != null){
													 if(ctrl.css("display") == "none"){
														 text = "";
														 dataField = "";
													 }else{
														 text = ctrl.val ? ctrl.val() : ""; 
													 }
												 }
												 ctrl = null;
											 }
											 ctrlObj = null;
									     }		
									}
								}
								var align = curCell.style.textAlign || "Left";
								var csp = curCell.colSpan == null? 1 : parseInt(curCell.colSpan || curCell.colspan, 10);
								ccount += csp;
								var cellNode = this.addCell(rowNode, text, {"colSpan":csp, "rowSpan":curCell.rowSpan, "fontSize":fs, "align":align, "lineAlign":"Center"});	
								if(dataField != null && dataField !== "") {
									if(isImg) {
										//二维码图片
										var dfv = query.ecp.getUI($("[id='"+dataField.replace(/\[[0-9]+\]./,"")+"']", $(mtab)), element);
										var imgUrl = dfv.getURL().replace(/&/g, "[AND]");

										this.option.barcode[imgUrl] = this.option.hasPrint;
										var width = imgUrl.match(/width=([0-9]+)/);
										if(width.length > 1) {
										 	width = width[1];
										} else {
										   	width = 100;
										}
										var height = imgUrl.match(/height=([0-9]+)/);
										if(height.length > 1) {
										  	height = height[1];
										} else {
										   	height = 100;
										}
										var imgNode = this.addImage(imgUrl, 0, 0, width, height, cellNode);
										var vn = imgNode.getNode("Value");
										if(vn != null) {
										    this.setDataField(vn, dataField);
										}
									} else {									
									    this.setDataField(cellNode, dataField);
									    var fmtAry = html.match(/format[sS]tyle[:=]['"]*([#*,]+)['"]/);
									    if(fmtAry != null && fmtAry.length > 1) {
									    	cellNode.setAttrib("formatStyle", fmtAry[1]);
									    }
									}
								} else if(isImg) {
									var imgUrl = html.match(/src=["']([^<>"']+)["']/);
									if(imgUrl != null) {
										imgUrl = imgUrl[1];
									}
									var width = html.match(/[wW][iI][Dd][Tt][Hh][=:](["'])?([\d]+)(px)?(["'])?/);
									if(width != null) {
										width = width[2];
									} else {
										width = maxHeight;
									}
									var height = html.match(/[hH][eE][iI][gG][hH][tT][=:](["'])?([\d]+)(px)?(["'])?/);
									if(height != null) {
										height = height[2];
									} else {
										height = maxHeight;
									}
									this.addImage(imgUrl, 0, 0, width, height, cellNode);
								} else if(text !== "" && curCell.offsetWidth > 0) {
									var ccw = parseInt(curCell.offsetWidth * ce, 10);
									if(tdws instanceof Array) {
										var cccsp = curCell.colSpan || curCell.colspan;
										if(cccsp !== "") {
											cccsp = 1;
										}
										cccsp = parseInt(cccsp, 10);
										ccsum = 0;
										for(var k = 0; k < cccsp; k++) {
											var cws = tdws[k + j];
											if(cws !== "") {
												ccsum += parseInt(cws, 10);
											}
										}
										if(ccsum > 0) {
											ccw = ccsum;
										}
									}
									var cch = this._getTextHeight(text, ccw, fs);
									if(cch > maxHeight) {
										maxHeight = cch;
									}
								}		
								cellNode = null;
							}//for j
							if(!hasData) {
								maxHeight = crow.offsetHeight;
							}
							rowNode.setAttrib("Height", maxHeight);
							rowNode = null;
						} else {
							ignoreRow++;
						}
					} //for i
					//获取列宽
					var rows = mtab.rows[rowMxIndex];
					for(var j = 0, clen = rows.cells.length; j < clen; j++) {
						var cells = rows.cells[j];
						var cw = cells.offsetWidth;
						if(params.maxColWidth != null && cw > params.maxColWidth) {
							cw = params.maxColWidth;
						}
						tdWidths[j] = cw;
						cells = null;
					}
					//重新计算宽度
					if(colSum > this.maxWidth || this.option.autoWidth == true) {
						var nColSum = 0;
						var len = tdWidths.length;
						for(var i = 0; i < len; i++) {
							tdWidths[i] = parseInt(tdWidths[i] * ce, 10);
							nColSum += tdWidths[i];
						}
						ce = this.maxWidth - nColSum;
						for(var i = 0; i < len && ce != 0; i++) {
							if(ce > 0) {
								tdWidths[i] ++;
								ce--;
							} else {
								tdWidths[i] --;
								ce++;
							}
						}
					}
					rows = null;
					if(tdws instanceof Array) {
						if(tdws.length < tdWidths.length) {
							for(var i = tdws.length, len = tdWidths.length; i < len; i++) {
								tdws.push(tdWidths[i]);
							}
						}
						if(tdws != null) {
						    this.setCellWidths(tabNode, tdws.join(","));
						} else {
							this.setCellWidths(tabNode, tdWidths.join(","));
						}
					} else {
						this.setCellWidths(tabNode, tdWidths.join(","));
					}
					var border = mtab.style.borderWidth || mtab.border || $(mtab).css("borderWidth");
					border = this._getPrintOption(po, ["border","Border"], border);
					//设置连线
					if(params.hasBorder != true && params.hasBorder !== "true"
							&& (border.indexOf("0px") >= 0 
								  || border == 0 
									|| border == null 
									   || border == "medium")) {
					    this.setNoBorder(tabNode, "true");
					}
					//设置表头列
					if(ml != null) {
						var hrs = "0";
						for(var i = 1; i < ml - rindex - ignoreRow; i++) {
							hrs += "," + i;
						}
						this.setHeadCount(tabNode, hrs, ml);
					}
					var rly = $(mtab).attr("relativey");
					rly = this._getPrintOption(po, ["Top","top"], rly);
					if(rly != null) {
						tabNode.setAttrib({"RelativeY":"true",
							               "RelativeTableID":"1",
							               "Y":rly});
				    }
					var lock = ""
					if(params.Lock != null && params.Lock !== "") {
						lock = params.Lock;
					}
					lock = this._getPrintOption(po, ["Lock","lock"], lock);
					if(lock !== "") {
					    tabNode.setAttrib("Lock", lock);
					}
					var np = $(mtab).attr("printinnewpage");
					np = this._getPrintOption(po, ["printinnewpage","printInNewPage","PrintInNewPage"], np);
					if(np == true || np === "true" || np === "True") {
					    tabNode.setAttrib("PrintInNewPage", "true");
					}
				} //if rindex
			}
			return tabNode
		},
		/**
		 * 添加表格.
		 * @param {number} top 表格顶点
		 * @param {number} left 表格左点
		 * @param {string} id
		 */
		addTable : function(option) {
			var tmpNode = this.PageNode.addNode("Table", undefined, this.getJsonValue(option.id,option.Id));
			var headCount = this.getJsonValue(option.headCount, option.HeadCount, 0);
			var heads = [];
			if(headCount > 0) {
				for(var i = 0; i < headCount; i++) {
					heads.push(i);
				}
			}
			tmpNode.setAttrib({"X":this.getJsonValue(option.left, option.Left, 0), 
				               "Y":this.getJsonValue(option.top, option.Top, 0),
				               "IsTD":this.getJsonValue(option.border, option.Border, 1) === 0,
				               "TdWidths": this.getJsonValue(option.tdWidths, option.TdWidths, []),
				               "Lock": this.getJsonValue(option.lock, option.Lock, "Center"),
				               "headRowCount": headCount,
				               "HeaderRows" : heads.join(","),
				               "lessRows": this.getJsonValue(option.lessRows, option.LessRows, 0)
				               });
			return tmpNode;
		},
		/**
		 * 添加行.
		 * @param {node} table 表格节点.
		 * @param {number} height 高度 
		 */
		addRow : function(table, height) {
			var tr = table.addNode("Tr");
			tr.setAttrib("Height", height);
			return tr;
		},
		/**
		 * 添加单元格.
		 * @param {node} row 行节点
		 * @param {string} text 内容
		 * @param {number} colSpan 占用列数
		 * @param {number} rowSpan 占用行数
		 * @param {number} fontSize 字体大小
		 * @param {string} align 横对齐 Left, Center, Right
		 * @param {string} lineAlign 列对齐 Top, Center, Bottom
		 */
		addCell : function(row, text, option) {
			var cellNode = row.addNode("Td", text);
			if(option == null) {
				option = {};
			}
			cellNode.setAttrib({"ColSpan":option.colSpan || 1,
				                "RowSpan":option.rowSpan || 1,
				                "Alignment":option.align || "Left", 
				                "LineAlignment":option.lineAlign || "Center",
				                "FontSize":option.fontSize || 11});
			return cellNode;
		},
		setCellWidths : function(table, widths) {
			table.setAttrib("TdWidths", widths);
		},
		setHeadCount : function(table, rowIndexs, count) {
			table.setAttrib("HeaderRows", rowIndexs);
			table.setAttrib("headRowCount", count);
		},
		setFixColumn : function(table, count) {
			table.setAttrib("FixColumnCount", count);
		},
		setDataField : function(obj, value, dfNode) {
			obj.setAttrib("dataField", value, dfNode);
		},
		setDataFields : function(obj, value) {
			return obj.setAttrib("dataFields", value);
		},
		getTableById : function(id) {
			return this.xmlDoc.getNode("Report/Page/Table&" + id);
		},
		getTextById : function(id) {
			return this.xmlDoc.getNode("Report/Page/Text&" + id);
		},
		setTop : function(node, top) {
			node.setAttrib("Y", top);
		},
		setLeft : function(node, left) {
			node.setAttrib("X", left);
		},
		getTop : function(node) {
			return node.getAttrib("Y");
		},
		getLeft : function(node) {
			return node.getAttrib("X");
		},
		getHeadCount : function(tabNode) {
			return tabNode.getAttrib("headRowCount");
		},
		getDataField : function(dataField) {
			if(dataField == null) {
			    return this.xmlDoc.dataField;
			} else {
				return this.xmlDoc.dataField[dataField];
			}
		},
		updateDataField : function(dataField, value) {
			this.xmlDoc.setDataField(dataField, value);
		},
		updateDataFields : function(dataFields, dataJson, pnode) {
			this.xmlDoc.setDataFields(dataFields, dataJson, pnode);
		},
		appendDataFields : function(dataFields) {
			return this.xmlDoc.appendDataFields(dataFields);
		},
		getDataFields : function() {
			var dfs = [];
			var dfjson = this.xmlDoc.dataFields;
			for(key in dfjson) {
				dfs.push(dfjson[key]);
			}
			return dfs;
		},
		hasDataFields : function(dataFields) {
			var dfs = this.xmlDoc.getDataFields(dataFields);
			return (dfs != null);
		},
		/**
		 * 设置页眉.
		 * @param {string} value 值
		 * @param {JSON} option 属性
		 * @param {boolean} option.isShowLine:显示下画线,
		 * @param {string} option.LineAlignment:纵对齐,
		 * @param {string} option.fontName:字体名称,
		 * @param {number} option.fontSize:字体大小,
		 * @param {boolean} option.I:I斜体
		 * @param {boolean} option.B:B粗体
		 * @param {boolean} option.U:U底线
		 * @param {boolean} option.S:S删除线
		 */
		setHeader : function(value, option) {
			if(value != null && value instanceof Array && value.length > 0) {
			    var ftNode = this.ReportNode.addNode("Header");
			    //设置各样式属性
			    if(typeof option == "object") {
			    	for(var key in option) {
			    		if(option[key] != null) {
			    			ftNode.setAttrib(key, option[key]);
			    		}
			    	}
			    }
			    if(value instanceof Array) {
			    	if(value[0] != null && value[0] !== "") {
			            ftNode.addNode("LeftValue", value[0]);
			        }
			        if(value[1] != null && value[1] !== "") {
			            ftNode.addNode("CenterValue", value[1]);
			        }   
			        if(value[2] != null && value[2] !== "") {
			            ftNode.addNode("RightValue", value[2]);
			        }
			    }			    
			}
		},
		/**
		 * 设置页脚.
		 * @param {string} value 值
		 * @param {JSON} option 属性
		 * @param {boolean} option.isShowLine:显示下画线,
		 * @param {string} option.LineAlignment:纵对齐,
		 * @param {string} option.fontName:字体名称,
		 * @param {number} option.fontSize:字体大小,
		 * @param {boolean} option.I:I斜体
		 * @param {boolean} option.B:B粗体
		 * @param {boolean} option.U:U底线
		 * @param {boolean} option.S:S删除线
		 */
		setFooter : function(value, option) {
			if(value != null && value instanceof Array && value.length > 0) {
			    var ftNode = this.ReportNode.addNode("Footer");
			    //设置各样式属性
			    if(typeof option == "object") {
			    	for(var key in option) {
			    		if(option[key] != null && option[key] != null) {
			    			ftNode.setAttrib(key, option[key]);
			    		}
			    	}
			    }
			    if(value instanceof Array) {
			    	if(value[0] != null && value[0] !== "") {
			            ftNode.addNode("LeftValue", value[0]);
			        }
			        if(value[1] != null && value[1] !== "") {
			            ftNode.addNode("CenterValue", value[1]);
			        }   
			        if(value[2] != null && value[2] !== "") {
			            ftNode.addNode("RightValue", value[2]);
			        }
			    }			    
			}
		},
		setPrinter : function(value) {
			if(value != null) {
				var pn = this.ReportNode.addNode("Printer");
				pn.setAttrib("Name", value);
				pn = null;
			}
		},
		setZoomValue : function(value) {
			if(value != null) {
				this.ReportNode.setAttrib("Scale", value);
			}
		},
		setRecordAPage : function(value) {
			if(value != null) {
				this.ReportNode.setAttrib("RowCountPerPage", value);
			}
		},
		setRowCountPerPage:function(tab, value) {
			tab.setAttrib("RowCountPerPage", value);
		},
		setNoBorder : function(tab, value) {
			tab.setAttrib("IsTD", value);
		},
		setPrintAllTable : function(value) {
			this.printAllTable = value;
		},
		getPrintAllTable : function() {
			return this.printAllTable;
		},
		getPrinters : function() {
			if(this.printers == null) {
				var reData = [];
				if(this.getBrowser("msie")) {
				     try{			     
					     var WshNetwork = new ActiveXObject("WScript.Network");
					     var oPrinters = WshNetwork.EnumPrinterConnections();
					     if (oPrinters.length < 1) {
					         this.utils.notify(this._i18n.qzz.noSetupPrinter)
					     }			     
					     for (var i = 0, j = 0; i < oPrinters.length; i += 2, j++) {
					    	 reData[j] = {};
					    	 reData[j].id = oPrinters.Item(i + 1);
					    	 reData[j].text = oPrinters.Item(i + 1);
					     }
					     WshNetwork = null;
					     oPrinters = null;
					} catch(e) {
						this.utils.notify(this._i18n.qzz.noPrinter);
					}
				} else {
					 var obj = this.getPrintObj();
			  	     try {
					     var result = obj.printerList();
					     if(result !== "") {
					    	 var prAry = result.split("&@");
					    	 if(prAry.length > 1) {
					    		 this.defPrinter = prAry[1];
					    	 }
					    	 prAry = prAry[0].split("&#");
					    	 for(var i = 0; i < prAry.length; i++) {
					    		 reData[i] = {};
						    	 reData[i].id = prAry[i];
						    	 reData[i].text = prAry[i];
					    	 }
					     }
			  	     } catch(e) {
			  	    	 this.utils.notify(this._i18n.qzz.noPrinter2);
			  	     }
				}
				this.printers = reData;
		  	}			
			return this.printers;
		},
		getDefPrinter : function() {
			if(this.defPrinter == null) {
				var bKey = "";
				try {
					if(this.getBrowser("msie")) {
						 var shell = new ActiveXObject("WScript.Shell");
					     var  bKey  = shell.RegRead("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device");
					     Key = bKey.split(",")
					     bKey = Key[0];
					} else {
						 bKey = this.defPrinter;
					}
				} catch(e) {
					this.utils.notify(this._i18n.qzz.noPrinter);
					bKey = "";
				}
				this.defPrinter = bKey;
			}			
			return this.defPrinter;
		},
		/**
		 * 调用com+控件.
		 * @param {string} name 传处com+的ole字符串，如'AutoUpdate.WebUpdate'(包括对象+接口) 或 应用程序如 FT_reg.exe,当执行exe时，默认只运行与dllAdapter.dll同目录的exe文件
		 * @param {string} method 方法名 如果是运行exe文件，可传入空
		 * @param {Array} params 传入参数数组，可不传
		 * @param {Array} property 传入属性数组格式[{name:'p1',value:'v1'},{name:'p2', value:'v2'}] 可不传
		 * @param {Boolean} ret 是否需要返回值 可不传，默认是true
		 * @param {string} 可传入类型 type如 dll, exe等，建议不传，目前默认解析dll和exe，
		 * @example 
		 *    var res = $.ecp.utils.activeInvoke('AutoUpdate.WebUpdate','GetMudVersion', [], []);
		 *    $.ecp.utils.activeInvoke('FT_reg.exe');
		 */
		activeInvoke:function(name, method, params, property, ret, type) {
		      var str = 'name:' + name + '\n';
		      if(method !== '') {
		        str += 'method:'  + method + '\n';
		      }
		      //解析参数
		      if(params instanceof Array && params.length > 0) {
		          var len = params.length;          
		          for(var i = 0; i < len; i++) {
		              str += 'params:';
		              var tp = typeof params[i];
		              if(tp  === 'number') {
		                  str += 'number\n';
		              } else if (tp === 'boolean') {
		                  str += 'boolean\n';
		              } else if (/^[0-9]+\-[0-9]+\-[0-9]+ [0-9]+:[0-9]+:[0-9]+(.[0-9]+)?$/.test(params[i])) {
		                  str += 'datetime\n';
		              } else if (/^[0-9]+\-[0-9]+\-[0-9]+$/.test(params[i])) {
		                  str += 'datetime\n';
		              } else {
		                  str += 'string\n'
		              }
		              str += params[i] + "\n";
		          }
		      }   
		      //解析属性   
		      if(property instanceof Array && property.length > 0) {
		          var len = property.length;          
		          for(var i = 0; i < len; i++) {
		              str += 'property:';               
		              str += property[i].name;  
		              var tp = typeof property[i].value;
		              if(tp  === 'number') {
		                  str += ':number\n';
		              } else if (tp === 'boolean') {
		                  str += ':boolean\n';
		              } else {
		                  str += ':string\n';
		              }
		              str += property[i].value + '\n';          
		          }
		      }
		      if(ret != false) {
		          str += 'return:true\n';
		      }
		      if(type !== '' && type != null) {
		          str = 'type:' + type + '\n' + str;
		      }
		      str += '\0';
		      //创建npapi的对象
		      var dllToolObj = null;
		      if (window.addEventListener) {    
		          dllToolObj = document.getElementById("dlltool");
		          if(dllToolObj == null) {
		              dllToolObj = document.createElement("embed");
			          dllToolObj.id = "dlltool";
			          dllToolObj.type = "application/rpygtooljs";
			          dllToolObj.width = 1;
			          dllToolObj.height = 1;
			          dllToolObj.style.position="absolute";
			          dllToolObj.style.top="0px";
			          dllToolObj.style.left="0px";
			          var ddd = document.getElementsByTagName("BODY");
			          ddd[0].appendChild(dllToolObj);
		          }
		      } else {
		          dllToolObj = new ActiveXObject('dllAdapter.dllAdapter');
		          dllToolObj.utf8 = 0;
		      }
		      var res = dllToolObj.caller(str);
		      dllToolObj = null;
		      return res;
		},
        getPrintObj : function() {
			if(this.printObj == null) {
				try {
					if(this.getBrowser("msie")) {
						this.printObj = new ActiveXObject("YGSoft.Finance.Printing.InvoicePrint");
					} else {
						var oprt =  document.createElement("embed");
						oprt.id = "dlltool1";
						oprt.type = "application/rpygtooljs";
						oprt.width = 1;
						oprt.height = 1;	
						oprt.style.position="absolute";
						oprt.style.top="0px";
						oprt.style.left="0px";
						if($ == null) {
							document.body.appendChild(oprt);
						} else {						
				  	        $("body").append(oprt);
						}
				  	    if(typeof oprt.caller == "function") {
				  	    	this.printObj = oprt;
				  	    	this.useTool = true;
				  	    } else {
				  	    	var nprt = document.createElement("embed");
				  	    	nprt.id = "dlltool2";
				  	    	nprt.type = "application/rpygecprtjs";
				  	    	nprt.width = 1;
				  	    	nprt.height = 1;
				  	    	nprt.style.position="absolute";
				  	    	nprt.style.top="0px";
				  	    	nprt.style.left="0px";
							this.useTool = false;
							if($ == null) {
								document.body.appendChild(nprt);
							} else {						
					  	        $("body").append(nprt);
							}
							this.printObj = nprt;
				  	    }
			   	    }
				} catch(e) {
					this.utils.notify(this._i18n.qzz.noReg + e);
					this.printObj = null;
				}
        	}
			return this.printObj;        	
		},
		/**
		 * 获得行最大值
		 */
		_getItemMaxHeight:function(df){
			var mh = parseInt(df.node.getAttrib("Height")||24, 10);
			for(var key in df.cnode) {
				var cn = df.cnode[key];
				if(cn.value != null) {
					//大小写处理
					var numupper = cn.getAttrib("numUpper");
					if(numupper != null && numupper !== "") {
						cn.value = this.numUpper(cn.value, numupper);
					}
					//加密处理
					var fstyle = cn.getAttrib("formatStyle");
					if(fstyle != null && fstyle !== "") {
						cn.value = this._getFormatStr(cn.value, fstyle);
					}
					var ch = this._getTextHeight(cn.value, 
										         this._getTdWidth(cn), 
										         parseInt(cn.getAttrib("FontSize")||9, 10));
					
					if(ch > mh) {
						mh = ch;
					}
				}
			}
			return mh;
		},
		//模板 + 数据包合并
		getPrintXmlData : function(formatXml, datas, callBack) {
			if(typeof formatXml === "string") {
				if(formatXml.indexOf("<?xml") < 0) {
					//formatXml = $.ecp.des.decodeBase64(formatXml, true); //encodeBase64
	        	}			
				var fxo = new printXmlDoc();
				fxo.setXml(formatXml);
				formatXml = fxo;
				fxo = null;
			}
			if(typeof datas != "object"){		
				return formatXml;
			}
			var dfs = formatXml.dataField;
			//更新所有dataFields
			for(var dataField in dfs) {
				if(datas[dataField] == null) {
					datas[dataField] = "";
				}
				//流程岗位信息.				
				if(dataField == "_postflow" || dataField == "_POSTFLOW") {
					var dataList = datas[dataField];
					if(dataList == null) {
						dataList = datas[dataField.toUpperCase()];
					}					
					if(dataList instanceof Array && dataList.length > 0) {				    	
						var td = dfs[dataField];
						var tab = td.pNode.pNode;
						var k = 0;
						var dlen = dataList.length;
						
						for(var i = 0, rlen = tab.nodeAry.length; i < rlen && k < dlen; i++) {
							var tr = tab.nodeAry[i];
							for(var j = 0, clen = tr.nodeAry.length; j < clen && k < dlen; j++) {
								td = tr.nodeAry[j];
								var postName = dataList[k].postName || dataList[k].POSTNAME;
								var userName = dataList[k].userName || dataList[k].USERNAME || "";
								var val = postName + ":" + userName;								
								td.value = val;
								k++;								
							}
							tr = null;
						}
						td = null;
						tab = null;						
				    }
				} else {
					var cn = dfs[dataField];
					var cvl = datas[dataField]
					if(cvl == null || cvl === "") { 
						cvl = datas[dataField.toUpperCase()]; 
						if(cvl == null) { 
							cvl = ""; 
						} 
					}
					cn.value = cvl;
					var numupper = cn.getAttrib("NumUpper");
					if(numupper != null && numupper !== "") {
						cn.value = this.numUpper(cn.value, numupper);
					}
					var fstyle = cn.getAttrib("formatStyle");
					if(fstyle != null && fstyle !== "") {
						cn.value = this._getFormatStr(cn.value, fstyle);
					}
					if(cn.name === "Td") {
						var mh = this._getTextHeight(cn.value, 
						         this._getTdWidth(cn), 
						         parseInt(cn.getAttrib("FontSize")||9, 10));
						var ch = parseInt(cn.pNode.getAttrib("Height"), 10);
						if(mh > ch) {
							ch = mh;
						}
						cn.pNode.setAttrib("Height", ch);
					}
					var cdf = cn.childDataField;
					if(cdf != null) {
						for(var i = 0, len = cdf.length; i < len; i++) {
							var ccn = cdf[i];
							ccn.value = cvl;
							var numupper = ccn.getAttrib("NumUpper");
							if(numupper != null && numupper !== "") {
								ccn.value = this.numUpper(ccn.value, numupper);
							}
							var fstyle = ccn.getAttrib("formatStyle");
							if(fstyle != null && fstyle !== "") {
								ccn.value = this._getFormatStr(ccn.value, fstyle);
							}
							if(ccn.name === "Td") {
								var mh = this._getTextHeight(ccn.value, 
								         this._getTdWidth(ccn), 
								         parseInt(ccn.getAttrib("FontSize")||9, 10));
								var ch = parseInt(ccn.pNode.getAttrib("Height"), 10);
								if(mh > ch) {
									ch = mh;
								}
								ccn.pNode.setAttrib("Height", ch);
							}
							ccn = null;
						}
					}
				}
			}
			//更新所有子表数据
			dfs = formatXml.dataFields;
			var defHeight = 25;
			if(dfs != null && dfs.length > 0) {
				var tmp = null,k = 0, rowNode = dfs[0].node;
				var count = dfs.length;
				for(var i = 0; i < count; i++) {
					var df = dfs[i];
					//tmp 为空， 或name不一样，或不是同一张表
					if(tmp == null || tmp.name != df.name || tmp.node.pNode.index != df.node.pNode.index) {
						//更新普通行				
						var dataField = df.name;
						var items = datas[dataField];
						if(items == null) { 
							items = datas[dataField.toUpperCase()]; 
						}
						if(items != null) {
							var j = 0, len = items.length;
							for(; j < len ; j++) {
								if(j > 0) {
									rowNode = formatXml.appendDataFields(df);
									rowNode.setAttrib("Height", defHeight);
								} else {
									defHeight = rowNode.getAttrib("Height");
									if(defHeight == null || defHeight === "") {
										defHeight = 25;
									}
								}
								var item = items[j];
								//添加序号显示
								if(item != null && item.rn == null) {
									item.rn = j + 1;
								}
								//var rh = this._getItemMaxHeight(df);
								formatXml.setDataFields(df, item);	
								var rh = this._getItemMaxHeight(df);
								rowNode.setAttrib("Height", rh);
							}
							//打印空白行.
							var tab = rowNode.pNode;
							if(tab != null) {
								var lessRows = tab.getAttrib("lessRows");
								if(lessRows == null) {
									lessRows = 1;
								}
								for(; j < lessRows; j++) {
									if(j > 0) {
										rowNode = formatXml.appendDataFields(df);
										rowNode.setAttrib("Height", defHeight);
									} else {
										defHeight = rowNode.getAttrib("Height");
										if(defHeight == null || defHeight === "") {
											defHeight = 25;
										}
									}
									var item = {};
									//添加序号显示
//									if(item != null && item.rn == null) {
//										item.rn = j + 1;
//									}
									formatXml.setDataFields(df, item);
									rowNode.setAttrib("Height", defHeight);
								}
							}
						}
						
						k = 0;
					} else {
						//更新合计行				
						var dataField = df.name;
						var items = datas[dataField + "_sum"];
						if(items == null) {
							items = datas[dataField.toUpperCase() + "_sum"];
						}
						if(items != null) {						
						    formatXml.setDataFields(df, items[k]);
						}
						rowNode = df.node;
						var rh = this._getItemMaxHeight(df);
						if(rh < defHeight) {
							rh = defHeight;
						}
						rowNode.setAttrib("Height", rh);
						k++;
					}
					tmp = df;
				} //for
			}
			return formatXml;
		},
		/**
		 * 初始化数据包.
		 */
		initData : function(params, callBack) {
			if(params != null) {
				if(params.xmlStr != null && typeof params.xmlStr == "string") {
					this.xmlDoc.setXml(params.xmlStr);
				}			
			    this.xmlDoc = this.getPrintXmlData(this.xmlDoc, params.data);
			}
			//do init data
		    if(typeof(callBack) == "function") {
		    	callBack(params);
		    }
		},
		/**
		 * 执行打印数据.
		 * @param {String} printType 打印方式 Preview|Print
		 * @param {JSON} params 参数列表
		 */
		printData : function(printType, params, callBack) {
			 var _this = this;
			 //显示进度条
//			 if(params == null || params.printScheme == null 
//					 || params.printScheme.batchPrint !== true) {
//		  		$.blockUI({timeout:0,overlayCSS : {
//					backgroundColor : '#ffffff',
//					opacity : 0.5,
//					cursor : 'wait'
//				}});
//		  	 }
			 this.initData(params, function(prms) {
				 if(params != null && params.printScheme != null 
						 && params.printScheme.notPrint === true) {
					 
//				     if(params.printScheme.batchPrint !== true) {
//					     $.unblockUI();				 
//				     }
					 if(typeof callBack === "function") {
						 callBack(_this.xmlDoc.toString(true));
					 }
				 } else {
//					 try {
//						 var _href = window.location.href,
//						     _formatId = $.ecp.utils.getArgument(_href,"formatid"),
//							 _cid = $.ecp.utils.getArgument(_href,"classId");
//							 _tid = $.ecp.utils.getArgument(_href,"typeId");
//						  var _msg = "打印预览页面:"+document.title;						  
//						  if(_cid != null && _cid !== "") {
//							  _msg += ",classId:"+_cid;
//						  }
//						  if(_tid != null && _tid !== "") {
//							  _msg += ",typeId:"+_tid;
//						  }						  
//						  if(_formatId != null && _formatId !== "") {
//							  _msg += ",formatId:"+_formatId;
//						  }
//					      $.ecp.auditService.addAuditLog("ecp.operator.system.web@print@printBean", _msg);							 
//					 }catch(e){
//						 this.utils.notify("保存审计日志记录失败。");
//					 }
					 if(_this.getBrowser("msie")) {
				  		 var obj = _this.getPrintObj();
				  		 if(obj != null) {
					  		 try {
					  			 _this.xmlStr = _this.xmlDoc.toString();
					  			 var lh = _this._getLocation() + "/";
					  			 if(lh !== "") {
					  				_this.xmlStr.replace(/[hH][tT][tT][pP]:\/\/[0-9]+.[0-9]+.[0-9]+.[0-9]+:[0-9]+\//g,lh); 
					  			 }					  			 
						  	     if(printType === "Preview") {
						  	         obj.Preview(_this.xmlStr, 1, 1, 0, "");
						  	     } else {
						  	         //smb添加了打印份数功能，
						  	    	 var str = _this.xmlStr;					  	    	 
						  	         obj.Print(str, 1, 1, 0, "");			  	         
						  	     }
					  	     } catch(e) {
					  	    	_this.utils.notify(_this._i18n.qzz.noReg + e.message);
					  	    	if(_this.xmlStr != null) {
					  	    	    _this.logInfo(_this.xmlStr);
					  	    	}
					  	     }
				  	     }		
				  		 if(params != null && params.printScheme != null && typeof params.printScheme.callBack === "function") {
				  			params.printScheme.callBack(params);
				  	     } else if(prms != null && typeof prms.callBack == "function") {
				  	    	 prms.callBack(prms);
				  	     }
//				  		 if(params == null || params.printScheme == null 
//					         || params.printScheme.batchPrint !== true) {
//				  		     $.unblockUI();
//					     }
				  		 if(typeof callBack == "function") {
				  			 callBack(_this.xmlDoc.toString(true));
				  		 }
				  	 } else {
				  	     try {
				  	         //给字符串添加结束符，因为chrome会自动增加乱码在字符串后面.
				  	    	 _this.xmlStr = _this.xmlDoc.toString();
				  	    	 var lh = _this._getLocation() + "/";
				  			 if(lh !== "") {
				  				_this.xmlStr = _this.xmlStr.replace(/[hH][tT][tT][pP]:\/\/[0-9]+.[0-9]+.[0-9]+.[0-9]+:[0-9]+\//g,lh); 
				  			 }						  	    	 
				  	    	 var pcount = 1;
				  	    	 _this.activeInvoke("YGSoft.Finance.Printing.InvoicePrint",printType,[_this.xmlStr, 1, 1, 0, ""]);
				  	    	 if(params != null && params.printScheme != null && typeof params.printScheme.callBack === "function") {
								params.printScheme.callBack(params);
						  	 } else if(prms != null && typeof prms.callBack == "function") {
					  	    	 prms.callBack(prms);
					  	     }
//						  	    	 if(params == null || params.printScheme == null 
//					                     || params.printScheme.batchPrint !== true) {
//						  	    	     $.unblockUI();	
//					                 }
							 if(typeof callBack == "function") {
					  			 callBack(_this.xmlDoc.toString(true));
					  		 }
				  	    	 return;
						 } catch(e) {
							 _this.utils.notify(_this._i18n.qzz.noReg);
							 if(_this.xmlStr != null) {
								    _this.logInfo(_this.xmlStr);
							 }
						 }
//								 if(params == null || params.printScheme == null 
//					                 || params.printScheme.batchPrint !== true) {
//								     $.unblockUI();
//					             }
						 if(typeof callBack == "function") {
				  			 callBack(_this.xmlDoc.toString(true));
				  		 }
				  	 }//browser
				 }//noePrint	 
			});			 
		}
    });
    function getPrintInstance() {
    	return new qzz.print.bean();
    }					  				
    if($ != null) {				  				
	    $.getPrintInstance = function() {
			return new qzz.print.bean();
	    };  
    }